问题描述
我正在尝试使用dozer 4.1在类之间进行映射。我有一个如下所示的源类:
I am trying to use dozer 4.1 to map between classes. I have a source class that looks like this:
public class initRequest{
protected String id;
protected String[] details
}
我有一个目标类看起来像这样:
I have a destination class that looks like this:
public class initResponse{
protected String id;
protected DetailsObject detObj;
}
public class DetailsObject{
protected List<String> details;
}
所以基本上我希望将details数组中的字符串填充到List中在Details对象中。
So essentially i want the string in the details array to be populated into the List in the Details object.
我尝试过这样的映射:
<mapping wildcard="true" >
<class-a>initRequest</class-a>
<class-b>initResponse</class-b>
<field>
<a is-accessible="true">details</a>
<b is-accessible="true">detObj.details</b>
</field>
</mapping>
但我收到此错误:
Exception in thread "main" net.sf.dozer.util.mapping.MappingException: java.lang.NoSuchFieldException: detObj.details
at net.sf.dozer.util.mapping.util.MappingUtils.throwMappingException(MappingUtils.java:91)
at net.sf.dozer.util.mapping.propertydescriptor.FieldPropertyDescriptor.<init>(FieldPropertyDescriptor.java:43)
at net.sf.dozer.util.mapping.propertydescriptor.PropertyDescriptorFactory.getPropertyDescriptor(PropertyDescriptorFactory.java:53)
at net.sf.dozer.util.mapping.fieldmap.FieldMap.getDestPropertyDescriptor(FieldMap.java:370)
at net.sf.dozer.util.mapping.fieldmap.FieldMap.getDestFieldType(FieldMap.java:103)
at net.sf.dozer.util.mapping.util.MappingsParser.processMappings(MappingsParser.java:95)
at net.sf.dozer.util.mapping.util.CustomMappingsLoader.load(CustomMappingsLoader.java:77)
at net.sf.dozer.util.mapping.DozerBeanMapper.loadCustomMappings(DozerBeanMapper.java:149)
at net.sf.dozer.util.mapping.DozerBeanMapper.getMappingProcessor(DozerBeanMapper.java:132)
at net.sf.dozer.util.mapping.DozerBeanMapper.map(DozerBeanMapper.java:94)
我如何映射它以使其有效?
How can i map this so that it works?
推荐答案
问题解决了......
Problem solved...
-
is-accesible允许更新对象而不管访问修饰符和getter / setter的存在(对于使用JAXB生成的对象至关重要)
is-accesible allows an object to be updated regardless of access modifier and presence of getters/setters (essential for objects generated using JAXB)
dot深度映射的表示法用于访问嵌套对象
"dot" notation for deep mapping works to access nested objects
组合这两者是一个在Dozer中不起作用的功能(可能是在较新的版本中)
Combining the two is a feature that does not work in Dozer (maybe it does in a newer version)
解决方案...
修改xsd,使得不需要深度映射。这不是我理想的解决方案,但它比为每个对象编写自定义转换器更好
solution...modify the xsd such that the deep mapping is not required. This is not my ideal solution but its better than writing a custom converter for every object
这篇关于推土机深度映射不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!