简体   繁体   中英

Dozer - map child elements

I have 2 Java objects, each contains a List of different Java objects. Using Dozer, I need to map the data from one object to another object. Can anyone help me pa the data from the FromPerson object to the ToPerson object? I am able to map the personList (6 in total) but not its fields.

class From{
List<FromPerson> personList;
}

class FromPerson{
String name;
}

class To{
List<ToPerson> personList;
}

class ToPerson{
String toPersonName;
}

    <mapping>
        <class-a>com.From</class-a>
        <class-b>com.To</class-b>
    </mapping>

Since both are list , if you are sure about first object of fromPerson list should map to first object of toPerson list, it is possible,Please see below code, it is working code

 <mapping>
    <class-a>com.FromPerson</class-a>
    <class-b>com.ToPerson</class-b>
    <field>
        <a>name</a>
        <b>toPersonName</b>
    </field>
</mapping>
<mapping>
    <class-a>com.From</class-a>
    <class-b>com.To</class-b>
    <field>
        <a>personList</a>
        <b>personList</b>
        <b-hint>com.ToPerson</b-hint>
    </field>
</mapping>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM