Marshalling Error: A cycle is detected in the object graph.

By | 2015年3月11日

在WebService编程传输对象的时候出现:Marshalling Error: A cycle is detected in the object graph. This will cause infinitely deep XML 。

这是由于对象中有关联造成的,可以通过在get方法上注解@XmlTransient来取消对某个属性的序列化。

package com.renyiwei.wydns.domain;

import javax.xml.bind.annotation.XmlTransient;

/**
*这是一个产品可选信息配置的类,绑定在产品栏目上,所以它和产品栏目有多对一的关联关系
*而产品栏目和它又有一对多的关联关系,所以会造成循环
**/
public class ProductOption {
//编号
private Long id;
//绑定的栏目编号
private ProductCategory category;
//绑定的字段
private String fieldname;
//输入类型
private String fieldtype;

public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
/*在这里注解*/
@XmlTransient
public ProductCategory getCategory() {
return category;
}
public void setCategory(ProductCategory category) {
this.category = category;
}
public String getFieldname() {
return fieldname;
}
public void setFieldname(String fieldname) {
this.fieldname = fieldname;
}
public String getFieldtype() {
return fieldtype;
}
public void setFieldtype(String fieldtype) {
this.fieldtype = fieldtype;
}

}