Andres
Andres

Reputation: 45

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?

Upvotes: 0

Views: 2453

Answers (2)

lance-java
lance-java

Reputation: 27958

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>

Upvotes: 1

lance-java
lance-java

Reputation: 27958

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.

Upvotes: 0

Related Questions