开发者

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&g开发者_Python百科t; 
    <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.


go one level deeper. like this

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

<mapping>
    <class-a>{class of object @ nameparts[0]}</class>
    <class-b>OrderShippingDetail</class-b>
    <field><a>name</a><b>firstname</b></field>
</mapping>

this works as a work-around. I've used this trick to make it work at some places.


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜