我使用休眠检索兄弟列表
public class Brother {
public int brotherId;
public string name;
public List<Brother> brothers;
public Brother()
{
brothers = new ArrayList<Brother>();
}
//Getter Setter
}
Hibernate 在兄弟列表中使用惰性选择进行配置,这在 Java 端有效,
但问题是当我想将 Brother 对象序列化为 JSON 时。
I've got org.codehaus.jackson.map.JsonMappingException: Infinite recursion (StackOverflowError)
例如,布莱恩可以让马克成为兄弟,反之亦然......
我怎样才能解决它?有什么方法可以指示杰克逊库的最大递归数?
我的代码,非常简单。
Brother brother = this.myservice.getBrother(4);
ObjectMapper mapper = new ObjectMapper();
System.out.println(mapper.writeValueAsString(brother));
问题的产生是因为循环引用.
Since Jackson 1.6
您可以使用两个注释来解决无限
递归问题,在不忽略 getter/setter 的情况下
序列化:@JsonManagedReference and @JsonBackReference.
refer here https://stackoverflow.com/a/18288939/286588了解更多
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)