Hi,
I have a problem with JSON-serialization of my JAXB-annotated classes using
JSONMarshaller class.
I use the Notation.MAPPED notation for JSON.
Some of my JAXB annotated classes are using @XmlID and @XmlIDRef annotations
and in my object graph, some objects refer to others. Some times, these
references are circular, i.e. object A refers to B and B in turn refers to
A.
If I use the usual JAXB serialization to XML with the same classes and
object graph, everything works just fine. I can first marshall into XML and
then unmarshall, and I get an object that is structurally the same.
But when I select JSON and use MAPPED format, the following thing happens:
- marshalling works fine
- but unmarshalling from JSON sometime returns wrong results. Specifically,
it looses some elements of the object graph for the cases, where circular
dependencies are present. For example, when it reads the whole graph and at
some point it reads A which refers to B, but B is not seen yet, the
unmarshaller would assign null to the reference to B inside A. Later B is
read, but this reference from A to B is never updated.
BTW, BadgerFish serialization works with the same classes and objects
properly. But it produces rather ugly looking JSON, which is bad for my
specific application. My goal is to create JSON-representation of my objects
and to store it inside MongoDB, which is a JSON-based NoSQL database.
Unfortunately, BadgerFish format is rather bad for queries on JSON
documents, where element names are supposed to be used. Therefore,
preserving proper names for elements and attributes is very important.
Questions:
1) Is it a known problem with JSON Mapped marshalling/unmarshalling?
2) May be some sort of a pass for resolving references should be done on the
JSON structure, once all elements are read and known? In this case, all
correct references could be resolved.
3) Are there any other ways to do proper JSON marshalling/unmarshalling for
object graphs and classes with circular dependencies?
Thanks in advance for any feedback!
--
View this message in context: http://n2.nabble.com/Problem-with-circular-dependencies-when-marshalling-to-JSON-my-JAXB-annotated-classes-tp4938441p4938441.html
Sent from the Jersey mailing list archive at Nabble.com.