在我的应用程序中,我有Dozer映射,如下所示:
<mapping>
<class-a>java.util.HashMap</class-a>
<class-b>org.mycompany.TargetClass</class-b>
<field custom-converter="org.example.MyConverter">
<a>this</a>
<b>anotherField</b>
</field>
</mapping>
MyConverter
是ConfigurableCustomConverter
的实例:
public class MyConverter implements ConfigurableCustomConverter {
private String parameter;
@Override
public Object convert(
Object existingDestinationFieldValue,
Object sourceFieldValue,
Class<?> destinationClass,
Class<?> sourceClass) {
// sourceClass is always java.lang.Object and
// sourceFieldValue is always null!!!
}
@Override
public void setParameter(String parameter) {
this.parameter = parameter;
}
}
为什么在源内评论中发现了事情?
答案 0 :(得分:4)
您需要告诉推土机地图的哪个键应该映射到b.anotherField
,类似
<field custom-converter="org.example.MyConverter">
<a key="foobar">this</a>
<b>anotherField</b>
</field>