Dozer を使用していくつかの Bean をマッピングしていますが、理解できないマッピングがあります。
ここに私のクラスがあります:
class A{
private ComplexeType type;
//Constructors & getters
}
class B{
private String[] type;
//Constructors & getters
}
class ComplexteType{
private List<String> list;
//Getter for the list, no constructor
}
クラス A をクラス B にマップするにはどうすればよいですか?
xmlを使用して、クラスAのフィールド型をクラスBのフィールド型にマッピングしたいと考えています。
xml ファイルは次のとおりです。
<mapping>
<class-a>A</class-a>
<class-b>B</class-b>
<field custom-converter="AToBCustomConverter">
<a>type</a>
<b>type</b>
</field>
</mapping>
そして、これが私の CustomConverter からの一口です
if (source == null) {
return null;
}
B dest = null;
if (source instanceof java.lang.String) {
// check to see if the object already exists
if (destination == null) {
dest = new A();
} else {
dest = (A) destination;
}
dest.getTypes().add((String) source);
return dest;
} else if (source instanceof B) {
String[] sourceObj = ((B) destination)
.getType()
.toArray(
new String[((B) destination)
.getType().size()]);
return sourceObj;
} else {
throw new MappingException(
"Converter StatResultCustomConverter used incorrectly. Arguments passed in were:"
+ destination + " and " + source);
}
}