I recently came across an exact scenario that OP has described here. Below was my solution.
Use JSOG (Javascript Object Graph) format to solve this.
Server Side
Use Jackson-Jsog plugin https://github.com/jsog/jsog-jackson
and annotate each class using below annotation.
@JsonIdentityInfo(generator=JSOGGenerator.class)
instead of the
@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "@id")
this would generate in JSOG format. (@id
and @ref
)
On the Client Side, use the jsog.js
convert the JSOG structure to the cyclic one using the below call
cyclicGraph = JSOG.decode(jsogStructure);