我有一个类在同一类下有 2 个不同的对象:
public class Customer {
//Source Attr
public Addr addr;
//target
public AddressDTO custAddr;
}
public class Addr {
public String street_Name;
public String home_Num;
public String post_code;
}
public class AddressDTO {
public String streetName;
public String homeNum;
public String postcode;
}
我正在尝试在客户对象中映射 Addr -> AddressDTO 对象:
ClassMapBuilder<?,?> classMapper = factory.classMap(Customer.class, Customer.class).classMap.field(addr.street_Name, custAddr.streetName).byDefault().register();
Customer source = new Customer();
source.setName("tester");
Addr addr = new Addr("streetname","123","456");
source.setAddr(addr);
Customer target = mapper.map(source,Customer.class);
当我运行这个时,我得到这个错误:
原因:java.lang.IllegalArgumentException:java.lang.String 是一个不受支持的源类,用于构造 com.domain.AddressDTO 的实例