@Override public void mapPath(final HttpRequestPacket requestPacket, final DataChunk path, final MappingData mappingData) throws Exception { mapper.map(requestPacket, path, mappingData); }
@RestController public UserRestController { @Resource private Myservice service; @Resource private Mapper mapper; // here you can use a dto @RequestMapping(...) public UserDto getUser(@RequestParam()Long userId){ User user = service.getUserBId(userId); return mapper.map(user,UserDto.class); } }
@Override public void mapPath(final HttpRequestPacket requestPacket, final DataChunk path, final MappingData mappingData) throws Exception { mapper.map(requestPacket, path, mappingData); }
@Override public void mapPath(final HttpRequestPacket requestPacket, final DataChunk path, final MappingData mappingData) throws Exception { mapper.map(requestPacket, path, mappingData); }
@Override public void mapPath(final HttpRequestPacket requestPacket, final DataChunk path, final MappingData mappingData) throws Exception { mapper.map(requestPacket, path, mappingData); }
Mapper mapper = chain.getFirstMap(); if (mapper != null) { mapper.map(key, value, chain.getMapperCollector(0, output, reporter), reporter); }
Mapper mapper = DozerBeanMapperSingletonWrapper.getInstance(); List<A> listOfA = getListofAObjects(); B[] arrayOfB = new B[listOfA.size()]; int i = 0; for (A a : listOfA) { arrayOfB[i++] = mapper.map(a, B.class); }
@Override public void mapPath(final HttpRequestPacket requestPacket, final DataChunk path, final MappingData mappingData) throws Exception { mapper.map(requestPacket, path, mappingData); }
@Override public void mapPath(final HttpRequestPacket requestPacket, final DataChunk path, final MappingData mappingData) throws Exception { mapper.map(requestPacket, path, mappingData); }
@Override public void mapPath(final HttpRequestPacket requestPacket, final DataChunk path, final MappingData mappingData) throws Exception { mapper.map(requestPacket, path, mappingData); }
@Override public void mapPath(final HttpRequestPacket requestPacket, final DataChunk path, final MappingData mappingData) throws Exception { mapper.map(requestPacket, path, mappingData); }
private Mapper mapper; @SuppressWarnings("unchecked") public Collection<MappedType> getMappedCollection(final Collection<SourceType> collection) { TopLevelCollectionWrapper<MappedType> wrapper = mapper.map( TopLevelCollectionWrapper.of(collection), TopLevelCollectionWrapper.class); return wrapper.getCollection(); }
@Override public void mapPath(final HttpRequestPacket requestPacket, final DataChunk path, final MappingData mappingData) throws Exception { mapper.map(requestPacket, path, mappingData); }
@Override public void mapPath(final HttpRequestPacket requestPacket, final DataChunk path, final MappingData mappingData) throws Exception { mapper.map(requestPacket, path, mappingData); }
@Override public void mapPath(final HttpRequestPacket requestPacket, final DataChunk path, final MappingData mappingData) throws Exception { mapper.map(requestPacket, path, mappingData); }
Mapper mapper = DozerBeanMapperSingletonWrapper.getInstance(); List<A> listOfA = getListofAObjects(); Iterator<A> iter = listOfA.iterator(); List<B> listOfB = new ArrayList<B>(); while(iter.hasNext()){ listOfB.add(mapper.map(iter.next(), B.class)); } B[] bs = listOfB.toArray(new B[listOfB.size()]);
public static <T, U> List<U> map(final Mapper mapper, final List<T> source, final Class<U> destType) { final List<U> dest = new ArrayList<>(); for (T element : source) { dest.add(mapper.map(element, destType)); } return dest; }
public class DozerHelper { public static <T, U> ArrayList<U> map(final Mapper mapper, final List<T> source, final Class<U> destType) { final ArrayList<U> dest = new ArrayList<U>(); for (T element : source) { if (element == null) { continue; } dest.add(mapper.map(element, destType)); } // finally remove all null values if any List s1 = new ArrayList(); s1.add(null); dest.removeAll(s1); return dest; } }
@Test public void testCollectionToIntMapping() { List<String> mappingFiles = new ArrayList<String>(); mappingFiles.add("com/mycompany/samples/dozer/somedozermapping.xml"); Mapper mapper = new DozerBeanMapper(mappingFiles); Source sourceObject = new Source(); sourceObject.setImages(Arrays.asList( "a", "b", "C" )); Destination destObject = mapper.map(sourceObject, Destination.class); assertEquals(3, destObject.getNumOfImages()); }