Unmarshalling JSON-null to nil-JAXBElement via Moxy

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Unmarshalling JSON-null to nil-JAXBElement via Moxy

Lukas Lentner



I put a question on stackoverflow, but nobody there can help me: https://stackoverflow.com/questions/45670953/how-can-moxy-while-unmarshalling-json-differentiate-between-a-absent-property-an


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

Please Help!

Thankx Lukas






Lukas Lentner, B. Sc.

St.-Cajetan-Straße 13

81669 München


Fon:     +49 / 89  / 44 38 61 27

Mobile:  +49 / 176 / 24 77 09 22

E-Mail:  [hidden email]

Website: www.LukasLentner.de


IBAN:    DE33 7019 0000 0001 1810 17

BIC:     GENODEF1M01 (Münchner Bank)


eclipselink-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit