Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAXB A cycle is detected in the object graph

Tags:

json

jaxb

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".

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.

Other web suggest using eclipselink MOXy, but MOXy cannot generate json.

like image 585
nathan21 Avatar asked Oct 11 '22 16:10

nathan21


1 Answers

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.

For More Information

  • http://bdoughan.blogspot.com/2010/07/jpa-entities-to-xml-bidirectional.html
  • http://blog.bdoughan.com/2011/08/json-binding-with-eclipselink-moxy.html
like image 114
bdoughan Avatar answered Oct 20 '22 06:10

bdoughan