Dozer Display InstantiationException Calendar Class
I am getting InstantationException when trying to match Date -> Calendar.
Simple test:
@Test
public void testConversion()
{
GregorianCalendar cal = new GregorianCalendar(2009, 2, 3);
Date sourceValue = cal.getTime();
DozerBeanMapper mapper = new DozerBeanMapper();
Object result = mapper.map(sourceValue, Calendar.class);
}
According to the docs, this is supported out of the box (although the calendar is abstract). Has anyone got any experience with this and been able to point out what I am doing wrong?
+2
source to share
2 answers
You're right. This is throwing InstantionException
(I believe this is a bug in dozer. Will you be logging it to your bug tracker?).
However. It works when you convert Date ↔ Calendar values not to root level. This test works for me (bulldozer 5.1):
public static class Source {
private Date value;
public void setValue(Date value) {
this.value = value;
}
public Date getValue() {
return value;
}
}
public static class Target {
private Calendar value;
public void setValue(Calendar value) {
this.value = value;
}
public Calendar getValue() {
return value;
}
}
@Test
public void testConversion()
{
final GregorianCalendar cal = new GregorianCalendar(2009, 2, 3);
Source source = new Source(){{ setValue(cal.getTime());}};
DozerBeanMapper mapper = new DozerBeanMapper();
Target result = (Target) mapper.map(source, Target.class);
assertEquals(cal.getTimeInMillis(), result.getValue().getTimeInMillis());
}
+2
source to share