I am using Moxy to marshall and unmarshal JSON and XML. My aim is a proper handling of a nil/null value in both formats with the same jaxb classes.
I took a XSD with an element having nillable="true" and minOccurs="0" and ran xjc on it. This gave me a jaxb-implementation-independent working xml binding. Now I tried
to get it to work with JSON and Moxy. The Marshaling side works fine, the unmarshalling is unable to differenciate between a absent json property and a property set to null.
I have got a JAXBElement member in my binding class and I can ask if the property was nil with isNil().
What I wish for: There are three cases: Element not given, Element set to nil (in XML) or null (in JSON), Element fully specified.
1.Absent properties should result in the java field set to java-null and vice versa.
2.Fully specified properties should result in a full set java field and vice versa.
3.XML Nil Elements should result in a java field with a JAXB-Element having getNil() = true
4.A Java field with an JAXBElement having nil=true should result in a xml element with xsi:nil=true
5.JSON property set to json-null should result in a java field with a JAXB-Element having getNil() = true
6.A Java field with an JAXBElement having nil=true should result in a json property set to json-null
Everything except 5 is working out of the box (which is really great, I love Moxy for that). But when I try to unmarshal a json null value I also get a java null value
on the field AS IF THE PROPERTY WAS NOT PART OF THE JSON.
How can I get Moxy to change this behaviour and respect that the property is part of the json and not hiding this fact.
I wish for a nil-initialized-jaxbelement value ...
Even better would be if the suggested solution would not break the implementation independence of the xml-only-binding, so our customers do not need to use Moxy if they
want to use our jaxb classses for xml-processing