JAXB 在对象图中检测到循环 [英] JAXB A cycle is detected in the object graph
问题描述
我想用 JAXB 将我的 pojo 转换为 json,我的 pojo 有一对多的关系,当我将我的 pojo 转换为 json 时,JAXB 生成错误在对象图中检测到循环.这将导致无限深的 XML".
I want to convert my pojo to json with JAXB, my pojo have one to many relation, and when i convert my pojo to json, JAXB generate error "A cycle is detected in the object graph. This will cause infinitely deep XML".
我从网上了解到,这个问题可以在@XmlID 和@XmlIDREF 的帮助下解决,但是有一个问题,我的Id 属性不是String 类型而是Long.据我所知,@XmlID 只能与 String 属性一起使用.
I read from web that, this problem can be solved with help from @XmlID and @XmlIDREF, but there is one problem, my Id attribute is not String type but Long. and as far as i know @XmlID can be used only with String property.
其他网站建议使用eclipselink MOXy,但是MOXy无法生成json.
Other web suggest using eclipselink MOXy, but MOXy cannot generate json.
推荐答案
正如你在问题中提到的 EclipseLink MOXy(我是技术主管)有 @XmlInverseReference
注解来解决双向关系的问题.从 EclipseLink 2.4 开始,MOXy 可以生成/使用 JSON.
As you mentioned in your question EclipseLink MOXy (I'm the tech lead) has the @XmlInverseReference
annotation to solve the problem of bidirectional relationships. As of EclipseLink 2.4 MOXy can produce/consume JSON.
更多信息
- http://bdoughan.blogspot.com/2010/07/jpa-entities-to-xml-bidirectional.html
- http://blog.bdoughan.com/2011/08/json-binding-with-eclipselink-moxy.html
这篇关于JAXB 在对象图中检测到循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!