Dozer is not calling my CustomConverter
no matter what I seem to do. I tried to put breakpoints and none of the CustomerConverter
code is ever called. The objects are converting, all fields but the ones linked to the CustomConverter
are working.
In my dozerBeanMapping.xml
file I have:
<configuration>
<custom-converters>
<converter type="converter.JodaDateToJavaDateConverter">
<class-a>org.joda.time.LocalDate</class-a>
<class-b>java.util.Date</class-b>
</converter>
</custom-converters>
</configuration>
<mapping type="one-way">
<class-a>data.SourceObject</class-a>
<class-b>data.DestinationObject</class-b>
<field custom-converter="converter.JodaDateToJavaDateConverter">
<a>myLocalDate</a>
<b>myJavaDate</b>
</field>
</mapping>
Then for the converter I have:
package converter;
public class JodaDateToJavaDateConverter implements CustomConverter
{
@Override
public Object convert(Object destination, Object source, Class<?> destinationClass, Class<?> sourceClass)
{
if(source == null)
return null;
if(!(source instanceof LocalDate))
throw new MappingException("Misconfigured/unsupported mapping");
return ((LocalDate)source).toDateTimeAtStartOfDay().toDate();
}
}
And for the Objects I have:
package data;
public class SourceObject
{
private LocalDate myLocalDate = LocalDate.now();
public void setMyLocalDate(LocalDate myLocalDate) { this.myLocalDate = myLocalDate; }
public LocalDate getMyLocalDate() { return myLocalDate; }
}
package data;
public class DestinationObject
{
private Date myJavaDate;
public void setMyJavaDate(Date myJavaDate) { this.myJavaDate = myJavaDate; }
public Date getMyJavaDate() { return myJavaDate; }
}
I don't think makes any difference but here is the code to start it all:
SourceObject mySourceObject = DozerBeanMapperSingletonWrapper.getInstance().map(DestinationObject, SourceObject.class);
I have no idea why my custom converters are not called...
UPDATE: I'm even more confused now. If the fields are the same name for both the Destination and Source Object then everything works. For whatever reason I can't map fields with different names...