【发布时间】:2017-11-03 14:47:39
【问题描述】:
我有以下课程:
public class A{
List<AA> aaList;
public A(List<AA> aaList){
this.aaList = aaList;
}
//getters and setters + default constructor
public class AA {
String aaString;
public AA(String aaString){
this.aaString = aaString;
}
//getters and setters + default constructor
}
}
我想拥有两个同一个类的对象,比如说:
A a = new A(Arrays.asList(new A.AA(null)));
A a2 = new A(Arrays.asList(new A.AA("test")));
当我将a 映射到a2 时,a2 应该保留为test,因为a 有一个null。
如何使用Orika 进行配置?
我尝试了类似的方法:
mapperFactory.classMap(A.AA.class, A.AA.class)
.mapNulls(false)
.byDefault()
.register();
mapperFactory.classMap(A.class, A.class)
.mapNulls(false)
.customize(new CustomMapper<A, A>() {
@Override public void mapAtoB(A a, A a2,
MappingContext context) {
map(a.getAAList(), a2.getAAList());
}
})
.byDefault()
.register();
提前致谢
【问题讨论】:
-
如何将
a映射到a2?我的意思是你试过了吗?我对此感到困惑。