3

I have a List<SelectConditionHeaderModel> .

When i am marshalling this list, I am getting an error :

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

My abstract Parent class.

@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;
    }

}

Header class extending the abstract 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;
    }

}

Condition class extending the Abstract Parent

@XmlRootElement
public class SelectConditionModel extends SelectConditionParentModel {

    String tableName;


    public String getTableName() {
        return columnFamily;
    }

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

}

Please help me out with this . I have also used XMLInverseReference but it seems that it is not working.

saurabh
  • 257
  • 1
  • 3
  • 12

2 Answers2

0

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

or you can put @XmlTransient to exclude the subgraph.

Xstian
  • 8,184
  • 10
  • 42
  • 72
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:

bdoughan
  • 147,609
  • 23
  • 300
  • 400