Question

I have two value objects (ValueObjectA and ValueObjectB), each with name1 and name2

Then I have two lists, each holds one of the value objects, which I plan to map with dozer.

As soon as I access the mapped 'listOfB', I get a Class Cast Exception, since dozer maps objects of type ValueObjectA into the list of ValueObjectsB.

Is it possible to map these two lists without iterating the lists and map object by object?

sample code:

...    
// prepare object A
List<ValueObjectA> lostOfA = new LinkedList();
ValueObjectA voA = new ValueObjectA();
voA.setName1("foo");
voA.setName2("bar");
lostOfA.add(voA);

// map object A to object B 
List<ValueObjectB> listOfB = new LinkedList();
mapper.map(lostOfA, listOfB);

for (ValueObjectB voB:listOfB ){
...
Was it helpful?

Solution

Not easily.

Take a look at this thread on the Dozer forum.

To quote:

"Nested collections are handled automatically, but you are correct that top level collections need to be iterated over. Currently there isn't a more elegant way to handle this."

OTHER TIPS

Try to define a mapping for both class . Dozer will use this mapping at run-time automatically and convert objects accordingly.

for example (psudo code) :

<mapping>
  <classA>ValueObjectA</classA> 
  <classB>ValueObjectB</classB> 
<mapping>

I guess the fields name in both class are same. If not you need to specify them in the above mapping.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top