Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » MOXy unmarshalling of nulls(Absent and explicitly-null fields are being interpretted identically)
MOXy unmarshalling of nulls [message #1082494] Thu, 08 August 2013 12:46 Go to next message
Lex Nemzer is currently offline Lex Nemzer
Messages: 3
Registered: August 2013
Location: Boston, MA
Junior Member
I'm seeing an error that was marked as fixed in Bug 307390 . I'm posting to the forum in case there's some configuration I'm missing or another simple solution.

Short version: My schema includes an element with minOccurs=0 and nillable=true. When unmarshalling a payload with content like <element xsi:nil="true" /> or { "element" : null }, I expect the result to be a JAXBElement with value=null and nil=true. Instead the result is null, which makes it impossible to tell the difference between the cases of "element is absent" and "element is explicitly set to null.

I'll add a longer version, with examples, to the thread as a follow-up.
Re: MOXy unmarshalling of nulls [message #1082604 is a reply to message #1082494] Thu, 08 August 2013 16:29 Go to previous messageGo to next message
Lex Nemzer is currently offline Lex Nemzer
Messages: 3
Registered: August 2013
Location: Boston, MA
Junior Member
Now the longer version.

I'm using MOXy 2.4.2, but the result is the same with 2.5.0 and 2.4.1. I also get the same result with JAXB 2.2 instead of 2.1 (which causes the @XmlElementRef annotations to include the parameter required=false).


I'm trying to simplify things as much as possible to reduce the variables. This is my trivial schema (note that the forum is forcing me to mangle the namespace URLs because they point outside of eclipse.org):
<xsd:schema
        xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
        xmlns:jaxb="http ://java.sun.com/xml/ns/jaxb"
        jaxb:version="2.1">
		
    <xsd:element name="MarshalElement">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="Nit" type="NillableIntegerType" minOccurs="0" nillable="true"/>
                <xsd:element name="Str" type="xsd:string" minOccurs="0" nillable="true"/>
                <xsd:element name="Itg" type="xsd:integer" minOccurs="0" nillable="true"/>
                <xsd:element name="Dec" type="xsd:decimal" minOccurs="1" nillable="true"/>
                <xsd:element name="Bol" type="xsd:boolean" minOccurs="0" nillable="true">
                <xsd:annotation>
                    <xsd:appinfo>
                        <jaxb:property generateIsSetMethod="true"/>
                    </xsd:appinfo>
                </xsd:annotation>
                </xsd:element>

            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>


XJC compiles that schema to this Java snippet:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "nit",
    "str",
    "itg",
    "dec",
    "bol"
})
@XmlRootElement(name = "MarshalElement")
public class MarshalElement {

    @XmlElementRef(name = "Nit", type = JAXBElement.class)
    protected JAXBElement<BigInteger> nit;
    @XmlElementRef(name = "Str", type = JAXBElement.class)
    protected JAXBElement<String> str;
    @XmlElementRef(name = "Itg", type = JAXBElement.class)
    protected JAXBElement<BigInteger> itg;
    @XmlElement(name = "Dec", required = true, nillable = true)
    protected BigDecimal dec;
    @XmlElementRef(name = "Bol", type = JAXBElement.class)
    protected JAXBElement<Boolean> bol;
	
  // SNIP: getter/setter for each element

    public boolean isSetBol() {
        return (this.bol!= null);
    }


When I unmarshal either of these payloads...
{"MarshalElement":
	{"Nit":null,"Str":null,"Itg":null,"Dec":null,"Bol":null}
}

<MarshalElement xmlns:xsi='http ://www.w3.org/2001/XMLSchema-instance'>
	<Nit xsi:nil="true" />
	<Str xsi:nil="true" />
	<Itg xsi:nil="true" />
	<Dec xsi:nil="true" />
	<Bol xsi:nil="true" />
</MarshalElement>


I would expect the resulting MarshalElement object to have the following properties:
* nit, str, itg, and bol contain a JAXBElement with value=null, nil=true
* dec contains null
* isSetBol() returns true

Instead, all of nit, str, itg, bol, and dec are null. And (obviously) isSetBol() returns false.
Re: MOXy unmarshalling of nulls [message #1083175 is a reply to message #1082604] Fri, 09 August 2013 11:27 Go to previous messageGo to next message
Denise Smith is currently offline Denise Smith
Messages: 11
Registered: July 2009
Junior Member
Hi

I've confirmed the behavior you are seeing and opened a bug based on your example to track the issue https://bugs.eclipse.org/414786. The other bug you mention is a similar issue but was particularly just for xsi:nil on the root level elements so the fix didn't include this use case.
Re: MOXy unmarshalling of nulls [message #1083183 is a reply to message #1083175] Fri, 09 August 2013 11:42 Go to previous message
Lex Nemzer is currently offline Lex Nemzer
Messages: 3
Registered: August 2013
Location: Boston, MA
Junior Member
Thanks Denise!

While waiting for my original post to be approved by the moderators, I also filed a bug (with the encouragement of the #eclipse IRC channel). It's probably worth checking https://bugs.eclipse.org/414721 and merging or closing it as a duplicate of yours.
Previous Topic:Example AttributeTransformer for @Transformation
Next Topic:Eclipselink 2.5 on Glassfish 3.1.2.2 possible without JavaEE7?
Goto Forum:
  


Current Time: Sat Apr 19 21:48:58 EDT 2014

Powered by FUDForum. Page generated in 0.02117 seconds