简体   繁体   中英

Dozer mapping of Lists of Complex Object

Is there a way to map one List of objects to one List of objects ids? I have the following objects:

public class Role implements Serializable {
    private List<Section> sections;
    //getters and setters
    ...
}

public class Section {
    private Long id;
    //getters and setters
    ...
}

public class RoleDTO implements Serializable {
    private List<Long> sections;
    //getters and setters
    ...
}

How can i map this with Dozer XML?

Note: This is not an answer... more of a wish

It would be nice if dozer supported groovy's spread operator . This would be a nice feature request

eg:

<field>
    <a>sections*.id</a>
    <b>sections</b>
</field>

You can use a custom converter

Dozer XML

<field custom-converter-id="mySectionsConverter">
  <a>sections</a>
  <b>sections</b>
</field>

Spring XML

<bean id="mapper" class="org.dozer.spring.DozerBeanMapperFactoryBean">
    <property name="mappingFiles" value="..." />
    <property name="customConvertersWithId">
        <map>
           <entry key="mySectionsConverter" value-ref="..." />
        </map>
    </property>
</bean>

Note: I'm just in the process of removing dozer from my application because I feel that it complicates things. In my opinion a simple java POJO converter class does a much better job than all this XML, custom converters and spring wiring. I've also found cases where it was impossible to reuse a value in a nested converter which caused multiple database hits which weren't required with the POJO solution.

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