agoncal-application-petstore-ee6
agoncal-application-petstore-ee6 copied to clipboard
embedded-jboss + rest => A cycle is detected in the object graph
When : curl -X GET http://localhost:8080/applicationPetstore/rs/catalog/products => Caused by: javax.xml.bind.MarshalException
- with linked exception: [com.sun.istack.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML: Product{id=15, name='Bulldog', description='Friendly dog from England'} -> Category{id=14, name='Dogs', description='A domesticated carnivorous mammal related to the foxes and wolves and raised in a wide variety of breeds'} -> Product{id=15, name='Bulldog', description='Friendly dog from England'}] at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:326) at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:251) at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:75) at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.writeTo(AbstractRootElementProvider.java:179) at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.writeTo(AbstractRootElementProvider.java:157) ... 33 more Caused by: com.sun.istack.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML: Product{id=15, name='Bulldog', description='Friendly dog from England'} -> Category{id=14, name='Dogs', description='A domesticated carnivorous mammal related to the foxes and wolves and raised in a wide variety of breeds'} -> Product{id=15, name='Bulldog', description='Friendly dog from England'} at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:252) at com.sun.xml.bind.v2.runtime.XMLSerializer.pushObject(XMLSerializer.java:541) at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:635) at com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(ArrayElementNodeProperty.java:69) at com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:172) at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:159) at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:356) at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:700) at com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:158) at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:356) at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:597) at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:338) at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:498) at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:323) ... 37 more
Same issue with GlassFish 3.1.2.2
[com.sun.istack.SAXException2: Un cycle est détecté dans le graphique d'objet. Cela générera un fichier XML d'une profondeur infinie : Category{id=40, name='Cats', description=' Small carnivorous mammal domesticated since early times as a catcher of rats and mice and as a pet and existing in several distinctive breeds and varieties'} -> Product{id=41, name='Manx', description='Great for reducing mouse populations'} -> Category{id=40, name='Cats', description=' Small carnivorous mammal domesticated since early times as a catcher of rats and mice and as a pet and existing in several distinctive breeds and varieties'}] at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:326) at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:251) at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:110) at com.sun.jersey.core.impl.provider.entity.XMLListElementProvider.writeList(XMLListElementProvider.java:157) at com.sun.jersey.core.provider.jaxb.AbstractListElementProvider.writeTo(AbstractListElementProvider.java:264) ... 32 more
Resolved adding @XmlTransient annotation on getters : org.agoncal.application.petstore.domain.Category.getProducts() and org.agoncal.application.petstore.domain.Product.getItems()