I am using Dozer to do object Mapping. Everything works reaaly well just that I’m not able to map this particular thing.
<mapping>
<class-a>User</class-a>
<class-b>UAUserBean</class-b>
<field>
<a>RightLst.Right</a>
<b>Rights</b>
<a-hint>Right</a-hint>
<b-hint>UARightBean</b-hint>
</field>
<field>
<a>RightLst.NumInLst</a>
<b>Rights.length</b>
</field>
</mapping>
//here RightLst is an object of a class and numInLst (int prop)
//rights is an array of objects
what i want to do is
lUser.getRightLst().setNumInLst(uaUserBean.getRights().length);
Any suggestions??
Thanks in advance.
User{
protected RightLst rightLst;
}
RightLst{
protected Integer numInLst;
protected Collection right = new ArrayList();
}
public class UAUserBean{
private UARightBean[] rights;
}
When you do this:
Dozer will try to access the first position of the
rightsarray and call the getter for the length property on an instance ofUARightBean(which is the type of the array), obviously the length property doesn’t exist inUARightBeanand Dozer will throw an Exception.I suggest to create a getter method in
UAUserBeanto return the length of therightsproperty, it would look like this:Mapping file:
If you can’t modify
UAUserBean, your last option would be a custom converter fromUARightBean[]toInteger, but it would look ugly.