Initially I was getting the below exception: I am using dozer 5.4. I am having the xerces jar file in my classpath. I am new to dozer so any kind of help is very much appreciated.
org.dozer.MappingException: java.lang.IllegalAccessException: Class org.dozer.util.ReflectionUtils can not access a member of class org.apache.xerces.jaxp.datatype.XMLGregorianCalendarImpl with modifiers "public"
I read from other posts from this site that the solution to the above is to write a custom converter for XmlGregorianCalender.
Below is the code for the custom converter. Currently the convertFrom method is getting invoked and all the values being passed are null.
Custom Converter:
import javax.xml.datatype.XMLGregorianCalendar;
import org.dozer.DozerConverter;
public class XMLGregorianCalendarCustomConvertor extends
DozerConverter<XMLGregorianCalendar, XMLGregorianCalendar>{
public XMLGregorianCalendarCustomConvertor() {
super(XMLGregorianCalendar.class, XMLGregorianCalendar.class);
// TODO Auto-generated constructor stub
}
@Override
public XMLGregorianCalendar convertTo(XMLGregorianCalendar source,
XMLGregorianCalendar destination) {
if (source == null) {
return null;
}
else{
return source;
}
}
@Override
public XMLGregorianCalendar convertFrom(XMLGregorianCalendar source,
XMLGregorianCalendar destination) {
if(destination == null){
return null;
}
else{
return destination;
}
}
}
Mapping xml
<configuration>
<custom-converters>
<converter type="com.code.user.XMLGregorianCalendarCustomConvertor" >
<class-a>javax.xml.datatype.XMLGregorianCalendar</class-a>
<class-b>javax.xml.datatype.XMLGregorianCalendar</class-b>
</converter>
</custom-converters>
</configuration>
How about copying it by reference ? If its an option for you you can do it like this: