0

我将我的配置详细信息保存在一个 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。

4

1 回答 1

0

由于 xstream 链接中使用了 XPATH_RELATIVE_REFERENCES:xstream 声明中的 xstream.codehaus.org/graphs.html 我们必须添加

  xstream.setMode(XStream.NO_REFERENCES);

而不是标记参考值将被放置。

于 2012-11-01T19:07:09.717 回答