@Test
public void testAutomaticCaseWithHint() throws Throwable {
final SimpleDateFormat df = new SimpleDateFormat(DATE_PATTERN);
MapperFactory factory = MappingUtil.getMapperFactory();
factory.registerDefaultFieldMapper(new DefaultFieldMapper() {
public String suggestMappedField(String fromProperty,
Type<?> fromPropertyType) {
if ("dateOfBirth".equals(fromProperty)) {
return "date";
} else if("date".equals(fromProperty)) {
return "dateOfBirth";
}
return null;
}
});
factory.getConverterFactory().registerConverter(new DateToStringConverter(DATE_PATTERN));
Person person = new Person();
person.setFirstName("Abdelkrim");
person.setLastName("EL KHETTABI");
person.setDate(df.parse("01/01/1980"));
person.setAge(31L);
PersonVO vo = factory.getMapperFacade().map(person, PersonVO.class);
Assert.assertEquals(person.getFirstName(), vo.getFirstName());
Assert.assertEquals(person.getLastName(), vo.getLastName());
Assert.assertTrue(person.getAge() == vo.getAge());
Assert.assertEquals("01/01/1980", vo.getDateOfBirth());