我有
public class CustomerA {
private String street;
public CustomerA() {
}
//get and set methods
}
public class CustomerB {
private IAddress address;
public CustomerB() {
}
//get and set methods
}
public class Address implements IAddress{
private String street;
public Address () {
}
//get and set methods
}
我想使用dozer
将CustomerA映射到CustomerB我的映射文件
<mapping>
<class-a>CustomerA</class-a>
<class-b bean-factory="CustomerBBeanFactory">CustomerB</class-b>
<field>
<a>street</a>
<b >address.street</b>
</field>
</mapping>
在CustomerBBeanFactory中,我返回一个CustomerB对象并将地址设置为新的Address()。不使用工厂意味着CustomerB无法从接口实例化地址类。
但是当我调用map方法
时,我会得到以下内容java.lang.NullPointerException
at org.dozer.util.ReflectionUtils.invoke(ReflectionUtils.java:323)
at org.dozer.propertydescriptor.GetterSetterPropertyDescriptor.writeDeepDestinationValue(GetterSetterPropertyDescriptor.java:259)
at org.dozer.propertydescriptor.GetterSetterPropertyDescriptor.setPropertyValue(GetterSetterPropertyDescriptor.java:87)
at org.dozer.fieldmap.FieldMap.writeDestValue(FieldMap.java:94)
at org.dozer.MappingProcessor.writeDestinationValue(MappingProcessor.java:895)
at org.dozer.MappingProcessor.mapFromFieldMap(MappingProcessor.java:349)
任何想法如何解决?
答案 0 :(得分:0)
看起来像set方法做了伎俩
<mapping>
<class-a>org.apache.camel.converter.dozer.service.Customer</class-a>
<class-b bean-factory="org.apache.camel.converter.dozer.model.CustomerBeanFactory">org.apache.camel.converter.dozer.model.Customer
</class-b>
<field>
<a>street</a>
<b set-method="setStreet">address.street</b>
</field>
</mapping>