|
Re: MOXy unmarshalling of nulls [message #1082604 is a reply to message #1082494] |
Thu, 08 August 2013 20:29 |
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.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02740 seconds