Mapper implements ResourceLoaderAware { public Object map(Object toMap) { if (toMap == null) { return null; } Class<?> mappedClass = mappings.get(toMap.getClass()); if (mappedClass != null) { return modelMapper.map(toMap, mappedClass); } else { return toMap; } }  void setPackages(List<String> packages); @PostConstruct void init(); @Override void setResourceLoader(ResourceLoader resourceLoader); Object map(Object toMap);  }
@Test public void shouldDetectAnnotationAndMapDTOToObject() { Movie m = new Movie("Iron Man 3", 2013, Quality.HD); Object dto = mapper.map(m); assertTrue(dto instanceof MovieInfo); assertEquals("Iron Man 3", ((MovieInfo)dto).getName()); assertEquals(new Integer(2013), ((MovieInfo)dto).getYear()); assertEquals("HD", ((MovieInfo)dto).getQuality()); }
@Test public void shouldDetectAnnotationAndMapObjectToDTO() { MovieInfo m = new MovieInfo("Iron Man 3", 2013, "HD"); Object dto = mapper.map(m); assertTrue(dto instanceof Movie); assertEquals("Iron Man 3", ((Movie)dto).getName()); assertEquals(new Integer(2013), ((Movie)dto).getYear()); assertEquals(Quality.HD, ((Movie)dto).getQuality()); }