我将我的配置详细信息保存在一个 xml 文件中,它的结构有点像这样
<A>
<b>
<name>xxxxx</name>
<age>xxxxx</age>
<c>
<someFeilds>yyyy</someFeilds>
</c>
<c>
<someFeilds>yyyy</someFeilds>
</c>
<c>
<someFeilds>yyyy</someFeilds>
</c>
</b>
<b>
<name>xxxxx</name>
<age>xxxxx</age>
<c>
<someFeilds>yyyy</someFeilds>
</c>
</b>
</A>
我能够将其编组到我的 DTO,其A
结构是
class A {
public ArrayList<B> bdtoInst;
}
class B {
public String name;
public String age;
public ArrayList<C> cdtoInst;
}
class C {
public String someFeilds;
}
Xstream 声明是
XStream xStream = new XStream();
xStream.alias("A", A.class);
xStream.addImplicitCollection(A.class, "bdtoInst");
xStream.alias("b", B.class);
xStream.addImplicitCollection(B.class, "cdtoInst");
xStream.alias("c", C.class);
我可以将它编组到我的 DTO,但是当我解组它时,我没有得到正确的格式,它是这样的:
<A>
<b>
<name>xxxxx</name>
<age>xxxxx</age>
<c>
<someFeilds>yyyy</someFeilds>
</c>
<c>
<someFeilds>yyyy</someFeilds>
</c>
<c>
<someFeilds>yyyy</someFeilds>
</c>
<c>
<someFeilds>yyyy</someFeilds>
</c>
</b>
<b>
<name>xxxxx</name>
<age>xxxxx</age>
<c reference="../../b/c"/>
</b>
</A>
我正在使用xstream-1.4.3.jar。