简体   繁体   中英

Jaxb cycle (infinite loop) marshalling error - MOXy and Spring OXM

I get a JAXB marshalling error (cycle infinite loop) - posted at end of this question.

I know it's due to a 2 way object reference and I have used EclipseLink MOXy JAXB marshaller in a test case to resolve this specifying ID and IDREF and specified the JAXB provider using a jaxb.properties file containing

javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory

However the production code uses Spring OXM and I cannot see how to achieve a similar result using this.

I have added a jaxb.properties file but it isn't being used - I know this because I add an empty file as a test and it doesn't complain (like it did on the prototype test case).

How do I specify the JAXB marshaller to use? It appears to be using:

org.eclipse.persistence.oxm.XMLMarshaller

whereas my working test case uses :

org.eclipse.persistence.jaxb.JAXBMarshaller

Exception: javax.xml.bind.MarshalException - with linked exception: [Exception [EclipseLink-25037] (Eclipse Persistence Services -
2.6.1.v20150916-55dc7c3):
org.eclipse.persistence.exceptions.XMLMarshalException Exception Description: A cycle is detected in the object graph. This will cause an infinite loop:
at org.eclipse.persistence.jaxb.JAXBMarshaller.marshal (JAXBMarshaller.java:487)

OK - to resolve this I specified (in the Spring OXM file)

<xml-inverse-reference mapped-by="myObject" 
    <xml-element xml-idref="true" 

I only added the xml-idref="true" relationship

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM