public class ModelMapperTest {
static class Source {
private DateTime dateProperty;
public DateTime getDateProperty() {
return this.dateProperty;
}
public void setDateProperty(DateTime dateProperty) {
this.dateProperty = dateProperty;
}
}
static class Destination {
private Date dateProperty;
public Date getDateProperty() {
return this.dateProperty;
}
public void setDateProperty(Date dateProperty) {
this.dateProperty = dateProperty;
}
}
@Test
public void testJodaTimeConversion() {
Source source = new Source();
source.setDateProperty(new DateTime());
ModelMapper modelMapper = new ModelMapper();
final AbstractConverter<DateTime, Date> jodaTimeConverter =
new AbstractConverter<DateTime, Date>() {
@Override
protected Date convert(DateTime source) {
return source == null ? null : source.toDate();
}
};