我有两个对象之间的双向关系.我有一个使用Jersey 1.17和Jackson 2.1.4的RESTful Web服务.我也在使用@JsonIdentityInfo注释(显然是错误的方式!)来阻止Json进入无限循环.但是,生成的Json仍然是两个对象之间的无限循环.
第一个对象是:
@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "@id")
public class Child {
private long value;
private Parent parent;
public long getValue() {
return this.value;
}
public void setValue(long value) {
this.value = value;
}
public Parent getParent() {
return this.parent;
}
public void setParent(Parent parent) {
this.parent = parent;
}
}
Run Code Online (Sandbox Code Playgroud)
第二个对象是:
@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "@id")
public class Parent {
private long value;
private Set<Child> childs = new HashSet<Child>(0);
public long getValue() {
return this.value; …Run Code Online (Sandbox Code Playgroud)