Reputation: 12748
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?
Upvotes: 5
Views: 4753
Reputation: 8230
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>
Upvotes: 1
Reputation: 12748
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.
Upvotes: 3