Search code examples
javahibernatecollectionsdozerobject-object-mapping

Dozer mapping non-Generic Collections to properties


I have some class structure as follows. These classes are hibernate classes so I cant change them.

//assume all getters & setters are present 
public class Order{ 
    private Customer customer; 
} 

public class Customer{ 
    // non generics set 
    private Set nameParts; 
} 

public class NamePart{ 
    private String id; 
    private String name; 
}

// target class
public class OrderShippingDetail{ 
    private String firstName; 
} 

mappying file

<mapping> 
    <class-a>Order</class-a> 
    <class-b>OrderShippingDetail</class-b> 
    <field> 
        <a>customer.nameParts[0].name</a> 
        <b>firstName</b> 
    </field> 
</mapping>

But this mapping of customer.nameParts[0].name dosent work as the dozer dosent know the object in the set. is there any work around.

If this can only be done by custom converter, a sample code template hint is appreciated.


Solution

  • I was going through the documentation and found that for non generic collections during deep mapping one can specify the objects using

    <field> 
        <a>customer.nameParts[0].name</a> 
        <b>firstName</b> 
        <a-deep-index-hint>com.example.Customer, com.example.NamePart</a-deep-index-hint>
    </field>