[英]Dozer mapping for objects without setters
public class ParentOne {
private List<ChildOne> child;
public List<ChildOne> getChild() {
if (child == null) {
child = new ArrayList<ChildOne>();
}
return child;
}
}
public class ParentTwo {
private List<ChildTwo> child;
public List<ChildTwo> getChild() {
if (child == null) {
child = new ArrayList<ChildTwo>();
}
return child;
}
}
DOZER映射
<mapping>
<class-a>ParentOne</class-a>
<class-b>ParentTwo</class-b>
<field>
<a is-accessible="true">child</a>
<b is-accessible="true">child</b>
</field>
</mapping>
public class Client {
public static void main(String[] args) {
ParentOne parentOne = new ParentOne();
parentOne.getChild().add(new ChildOne());
parentOne.getChild().add(new ChildOne());
ParentTwo parentTwo = dozerBeanMapper.map(parentOne, ParentTwo.class);
}
}
Parent类不包含列表的setter。 因此,我以直接访问字段的方式制作了推土机映射。 映射进行得很好,但是问题是映射parentTwo实例包含类型为ChildOne的子对象之后,应该是ChildTwo。
我有想念吗?
添加提示(有关更多信息,请参见此处 )。
<mapping>
<class-a>ParentOne</class-a>
<class-b>ParentTwo</class-b>
<field>
<a is-accessible="true">child</a>
<b is-accessible="true">child</b>
<a-hint>ChildOne</a-hint>
<b-hint>ChildTwo</b-hint>
</field>
</mapping>
您可能需要使用类的完全限定名称,而不仅仅是ChildOne
和ChildTwo
,但ChildTwo
,它应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.