Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Unmarshalling JSON-null to nil-JAXBElement via Moxy

Hi,

 

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

Deutschland

Fon:     +49 / 89  / 44 38 61 27

Mobile:  +49 / 176 / 24 77 09 22

E-Mail:  Kontakt@xxxxxxxxxxxxxxx

Website: www.LukasLentner.de

 

IBAN:    DE33 7019 0000 0001 1810 17

BIC:     GENODEF1M01 (Münchner Bank)

 


Back to the top