#119 Using multiple instances of CustomConverter

closed
None
5
2007-09-27
2007-08-08
No

Hi,

We've been using Dozer with Spring quite intensively now for a while and it does 95% of what we need. Thanks guys. Keep up the good work!

We'd like to be able to use multiple instances of the same CustomConverter implementation - each with different injected configurations, rather than write a specific CustomConverter implementation for each conversion. However, the Dozer mapping XML format doesn't allow us to indicate which instance of a particular class we want to invoke to do the conversion.

Would it be possible to add an alternate (or perhaps additional) attribute for the custom converter to the field definition so instead of the case below (that doesn't work when different conversions are required):

<field custom-converter="some.company.ConfigurableConverter">
<a>someField</a>
<b>someOtherField</b>
</field>

<field custom-converter="some.company.ConfigurableConverter">
<a>someField2</a>
<b>someOtherField2</b>
</field>

where some.company.ConfigurableConverter implements CustomConverter. You could specify:

<field custom-converter-id="convertSomeFieldToSomeOtherField">
<a>someField</a>
<b>someOtherField</b>
</field>

<field custom-converter-id="convertSomeField2ToSomeOtherField2">
<a>someField</a>
<b>someOtherField</b>
</field>

Where convertSomeFieldToSomeOtherField and convertSomeField2ToSomeOtherField2 both relate to instances of some.company.ConfigurableConverter

I don't expect that Dozer would magically consult Spring for these ID's. Instead, The custom-converter-id's could be mapped to the appropriate CustomConverter instances and injected into the dozer instance as shown for the property mappedCustomConverters (a bad name I know) below:

<bean id="myDozerBeanMapper"
class="net.sf.dozer.util.mapping.DozerBeanMapper" dependency-check="simple">
<property name="mappingFiles">
<list>
<value>someFile.xml</value>
</list>
</property>
<property name="customConverters">
<list>
<ref bean="configurableConverter"/>
</list>
</property>

<property name="mappedCustomConverters">
<map>
<entry key="convertSomeFieldToSomeOtherField" ref="configurableConverterBeanInstance1"/>
<entry key="convertSomeField2ToSomeOtherField2" ref="configurableConverterBeanInstance2"/>
</map>
</property>

<property name="eventListeners">
<list>
<ref bean="dozerEventListener"/>
</list>
</property>
</bean>

An alternative to the Map injection would be an additional interface that a custom converter could implement to return the id

eg. (Yet another bad name I know)

public interface CustomConverterWithId {
String getConverterId();
}

Dozer could then look through the List of injected CustomConverter's for an instance that advertised a matching id.

What do you guys think?

Cheers,

Stuntmunkee.

Discussion

  • Franz Garsombke

    Franz Garsombke - 2007-08-09

    Logged In: YES
    user_id=550744
    Originator: YES

    This is done and committed on the current_release branch. I still need to do the documentation.

     
  • Franz Garsombke

    Franz Garsombke - 2007-08-09

    Logged In: YES
    user_id=550744
    Originator: YES

    docs done.

     
  • Franz Garsombke

    Franz Garsombke - 2007-08-09
    • status: open --> pending
     
  • SourceForge Robot

    Logged In: YES
    user_id=1312539
    Originator: NO

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 45 days (the time period specified by
    the administrator of this Tracker).

     
  • SourceForge Robot

    • status: pending --> closed
     
  • Franz Garsombke

    Franz Garsombke - 2007-09-24
    • status: closed --> pending
     
  • Franz Garsombke

    Franz Garsombke - 2007-09-27
    • status: pending --> closed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks