3

我有一个List<SelectConditionHeaderModel>.

当我编组此列表时,出现错误:

javax.xml.bind.MarshalException
 - with linked exception:
[com.sun.istack.internal.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML

我的抽象父类。

@XmlRootElement
@XmlSeeAlso({ SelectConditionHeaderModel.class,
        SelectConditionModel.class })
public abstract class SelectConditionParentModel {

    @XmlInverseReference(mappedBy = "conditionList")
    SelectConditionParentModel parent;

    public SelectConditionParentModel getParent() {
        return parent;
    }

    public void setParent(HbaseSelectConditionParentModel parent) {
        this.parent = parent;
    }

}

扩展抽象父类的头类

@XmlRootElement
public class SelectConditionHeaderModel extends
        SelectConditionParentModel {

    List<SelectConditionParentModel> conditionList;

    String header;

    public List<SelectConditionParentModel> getConditionList() {
        return conditionList;
    }

    public void setConditionList(List<SelectConditionParentModel> condition) {
        this.conditionList = condition;
    }

    public String getHeader() {
        return header;
    }

    public void setHeader(String header) {
        this.header = header;
    }

}

扩展抽象父级的条件类

@XmlRootElement
public class SelectConditionModel extends SelectConditionParentModel {

    String tableName;


    public String getTableName() {
        return columnFamily;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

}

这个你能帮我吗 。我也使用过 XMLInverseReference,但它似乎不起作用。

4

2 回答 2

0

If you are using EclipseLink JAXB (MOXy) as your JAXB (JSR-222) provider then you can leverage our @XmlInverseReference extension to map your bi-directional relationship.

You can find a complete example on my blog:

于 2014-08-06T12:33:27.687 回答
0

Try to use this configuration based on @XmlID and @XmlIDREF.

or you can put @XmlTransient to exclude the subgraph.

于 2014-08-06T10:39:01.873 回答