JAXB在对象图中检测到循环 [英] JAXB A cycle is detected in the object graph

查看:79
本文介绍了JAXB在对象图中检测到循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用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属性不是字符串类型但很久。据我所知@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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆