Mapping Lists of objects with Dozer

user1323246 picture user1323246 · Jan 17, 2013 · Viewed 16.4k times · Source

I created a dozer mapping for ClassA to ClassB.

Now I want to map a List<ClassA> to a List<ClassB>.

Is it possible to just

mapper.map(variableListClassA, variableListClassB) 

or do I have to go over a loop, e.g.

for (ClassA classA : variableListClassA) {
    variableListClassB.add(mapper.map(classA, ClassB.class))
}

Answer

artbristol picture artbristol · Jan 17, 2013

You need to use the loop, because the type of the list is erased at runtime.

If both lists are a field of a class, you can map the owning classes.