我得到这个例外:
Field mapping error -->
MapId: null
Type: null
Source parent class: com.ParentObject
Source field name: field1
Source field type: class com.OnOff1BitEnum
Source field value: OFF
Dest parent class: com.SubParent
Dest field name: subParent.field2
Dest field type: java.lang.Boolean java.lang.NullPointerException
at org.dozer.util.ReflectionUtils.invoke(ReflectionUtils.java:270)
at org.dozer.propertydescriptor.GetterSetterPropertyDescriptor.getDeepSrcFieldValue(GetterSetterPropertyDescriptor.java:116)
at org.dozer.propertydescriptor.GetterSetterPropertyDescriptor.getPropertyValue(GetterSetterPropertyDescriptor.java:69)
at org.dozer.fieldmap.FieldMap.getDestValue(FieldMap.java:141)
这是映射字段:
<mapping>
<class-a>com.ParentObject</class-a>
<class-b>com.SubParent</class-b>
<field custom-converter="com.OnOffEnumToBooleanConverter">
<a>field1</a>
<b get-method="isField2">subParent.field2</b>
</field>
</mapping>
我使用的推土机版本是 5.4.0
更新:在这篇文章中添加了转换器代码。当我在这里设置一个断点时,这没有达到
public class OnOffEnumToBooleanConverter implements org.dozer.CustomConverter {
/**
* {@inheritDoc}
*/
@Override
public Object convert(Object dest, Object src, Class<?> destClass, Class<?> srcClass) {
if (src == null) {
return null;
}
if (src instanceof com.OnOff1BitEnum) {
boolean canonicalObject;
if ((com.OnOff1BitEnum) src == com.OnOff1BitEnum.ON) {
canonicalObject = true;
} else if ((com.OnOff1BitEnum) src == com.OnOff1BitEnum.OFF) {
canonicalObject = false;
} else { // Unreachable Code To Test
throw new MappingException("Converter " + this.getClass().getCanonicalName() + " used incorrectly. Arguments passed in were: "
+ dest + " and " + src);
}
return canonicalObject;
}
}