5

I am mapping two DTO objects through Dozer mapper. I am interested in choosing one value from list and map it to a single field in the destination file.

Is it possible to use mapping like this:

<field>
   <a>someList[0]</a>
   <b>someVariable</b>
</field>

It seems that b part can have a list[1].value type of approach, but I cannot get it to work when brackets are on a side. Where am I making it wrong?

mico
  • 12,730
  • 12
  • 59
  • 99

2 Answers2

3

Actually, you don't need more than suggested

<field>
    <a>someList[0]</a>
    <b>someVariable</b>
</field>

structure to achieve this. I had the problem other where: I did not call the correct map() function for that mapping on my code. I had several mappings and the map() call to this specific one was missing.

mico
  • 12,730
  • 12
  • 59
  • 99
1

Use the following mapping:

<mapping map-id="collectionMapping" type="one-way">
    <class-a>java.util.Collection</class-a>
    <class-b>java.util.Collection</class-b>
    <field>
        <a>this</a>
        <b set-method="add(java.lang.Object)" type="iterate">anything</b>
        <b-hint>your destination object type</b-hint>
    </field>
</mapping>
Rob
  • 4,927
  • 12
  • 49
  • 54
GingerHead
  • 8,130
  • 15
  • 59
  • 93
  • Why is `a` pointing to `this` and can this be applied to a situation where `b` is eg. a String? – mico Jul 19 '12 at 14:19
  • 1
    +1 for a detailed, fast answer. I go still for the simpler solution from the original question. Good to know also that this kind of generic approach is possible. – mico Jul 20 '12 at 08:34