What Java XML binding structure supports circular / circular dependencies?

I have two classes:

public class A { B refToB; } public class B { A refToA; } 

they do not have unique id fields (which are required for JAX-B XMLID and XMLIDREF).

Object instances:

 A a = new A(); B b = new B(); a.refToB = b; b.refToA = a; 

I want marshall a in XML to maintain a circular / circular dependency, for example:

 <a id="gen-id-0"> <b> <a ref-id="gen-id-0" /> </b> </a> 

One of the frameworks I found supports XStream: http://x-stream.imtqy.com/graphs.html

What other frameworks support this feature?

Are some JAX-B implementations supported?

+4
source share
2 answers

Note. I am an EclipseLink JAXB (MOXy) and a member of the JAXB Group (JSR-222) .

MOXy has the @XmlInverseReference extension for displaying bidirectional relationships.

A

 import javax.xml.bind.annotation; @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class A { @XmlElement(name="b") B refToB; } 

IN

 import javax.xml.bind.annotation; import org.eclipse.persistence.oxm.annotations.XmlInverseReference; @XmlAccessorType(XmlAccessType.FIELD) public class B { @XmlInverseReference(mappedBy="refToB") A refToA; } 

XML

The above class will be mapped to the following XML

 <a> <b/> <a> 

Additional Information

+2
source

A few years ago I worked with Betwixt. They claim support, see http://commons.apache.org/betwixt/faq.html#cycles

Alas, setting up a simple test hasn’t worked for me yet, the output is just <A id="1"><B/></A> , while the pointer to A in B is silently ignored. There must be some sort of matching parameter that I could not set ...

+1
source

Source: https://habr.com/ru/post/1392436/


All Articles