You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 5, 2019. It is now read-only.
ULL PRODUCT VERSION :
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) Server VM (build 19.1-b02, mixed mode)
JAXB version 2.1:
[INFO] JAXB API is loaded from the [jar:file:/usr/lib/jvm/java-6-sun-1.6.0.24/jre/lib/rt.jar!].
[INFO] Detected JAXB API version [2.1].
ADDITIONAL OS VERSION INFORMATION :
Linux extdivmoha-laptop 2.6.32-34-generic-pae #77-Ubuntu SMP Tue Sep 13 21:16:18 UTC 2011 i686 GNU/Linux
EXTRA RELEVANT SYSTEM CONFIGURATION :
(none)
A DESCRIPTION OF THE PROBLEM :
When the XJC compiler generates java binding classes from XML Schema elements that are declared optional (minOccurs="0") and nillable (nillable="true"), the resulting element should cause a JAXBElement field to be generated to allow JAXB binding class clients to distinguish between the element being absent and the element being explicitly declared with a nil value.
Unfortunately, in certain circumstance, this is not the case.
Example 1 (correct XJC binding):
XML schema element declaration is made by referencing a schema type:
<xsd:element name="NillableElement2" type="xsd:string" nillable="true" minOccurs="0"/>
Resulting JAXB binding class field:
@XmlElementRef(name = "NillableElement2", namespace = "urn:jaxb:sample", type = JAXBElement.class)
protected JAXBElement nillableElement2;
Example 2 (incorrect XJC binding):
XML schema element declaration is made by referencing a nillable element (in a sequence):
<xsd:element ref="NillableElement1" minOccurs="0"/>
(with the)
<xsd:element name="NillableElement1" type="xsd:string" nillable="true"/>
When an xml schema element declaration specifies minOccurs="0" and references a nillable element. Notice how the "nillableElement1" field is declared as a String, which does not provide any way of determining whether the XML instance element was not present, or it was declared as a nil value (xsi:nil attribute).
Furthermore, when an JAXB Class instance, containing this field declaration is marshalled: @xmlelement(name = "NillableElement1", nillable = true)
protected String nillableElement1;
And the field (nillableElement1) contains null, the resulting XML will ALWAYS generate a NILL reference:
Even though the two XML schema examples above are semantically identical, they cause different JAXB Binding to be generated, one of which (Example 2) has two major problems:
It cannot be determined (or defined) whether an optional nillable field is null or (explicit) nil.
When marshalled, a null field will cause a "nil" element to be generated.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use JAXB to generate binding classes of a schema (attached: sample.xsd)
Look at the resulting OptionalNillable.java class (attached).
See the difference between the nillableElement1 and nillableElement2 fields of the OptionalNillable.java class.
Full maven project with unit tests can be provided, upon request.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Given the XML schema declarations...
File: OptionalNillable.java
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4
// See http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2011.10.28 at 10:22:00 AM CEST
//
package jaxb.sample;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.jvnet.jaxb2_commons.lang.Equals;
import org.jvnet.jaxb2_commons.lang.EqualsStrategy;
import org.jvnet.jaxb2_commons.lang.HashCode;
import org.jvnet.jaxb2_commons.lang.HashCodeStrategy;
import org.jvnet.jaxb2_commons.lang.JAXBEqualsStrategy;
import org.jvnet.jaxb2_commons.lang.JAXBHashCodeStrategy;
import org.jvnet.jaxb2_commons.lang.JAXBToStringStrategy;
import org.jvnet.jaxb2_commons.lang.ToString;
import org.jvnet.jaxb2_commons.lang.ToStringStrategy;
import org.jvnet.jaxb2_commons.locator.ObjectLocator;
import org.jvnet.jaxb2_commons.locator.util.LocatorUtils;
/**
Java class for anonymous complex type.
The following schema fragment specifies the expected content contained within this class.
ULL PRODUCT VERSION :
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) Server VM (build 19.1-b02, mixed mode)
JAXB version 2.1:
[INFO] JAXB API is loaded from the [jar:file:/usr/lib/jvm/java-6-sun-1.6.0.24/jre/lib/rt.jar!].
[INFO] Detected JAXB API version [2.1].
ADDITIONAL OS VERSION INFORMATION :
Linux extdivmoha-laptop 2.6.32-34-generic-pae #77-Ubuntu SMP Tue Sep 13 21:16:18 UTC 2011 i686 GNU/Linux
EXTRA RELEVANT SYSTEM CONFIGURATION :
(none)
A DESCRIPTION OF THE PROBLEM :
When the XJC compiler generates java binding classes from XML Schema elements that are declared optional (minOccurs="0") and nillable (nillable="true"), the resulting element should cause a JAXBElement field to be generated to allow JAXB binding class clients to distinguish between the element being absent and the element being explicitly declared with a nil value.
Unfortunately, in certain circumstance, this is not the case.
Example 1 (correct XJC binding):
XML schema element declaration is made by referencing a schema type:
<xsd:element name="NillableElement2" type="xsd:string" nillable="true" minOccurs="0"/>
Resulting JAXB binding class field:
@XmlElementRef(name = "NillableElement2", namespace = "urn:jaxb:sample", type = JAXBElement.class)
protected JAXBElement nillableElement2;
Example 2 (incorrect XJC binding):
XML schema element declaration is made by referencing a nillable element (in a sequence):
<xsd:element ref="NillableElement1" minOccurs="0"/>
(with the)
<xsd:element name="NillableElement1" type="xsd:string" nillable="true"/>
Resulting JAXB binding class field:
@xmlelement(name = "NillableElement1", nillable = true)
protected String nillableElement1;
Conclusion (ref Example 2, above):
When an xml schema element declaration specifies minOccurs="0" and references a nillable element. Notice how the "nillableElement1" field is declared as a String, which does not provide any way of determining whether the XML instance element was not present, or it was declared as a nil value (xsi:nil attribute).
Furthermore, when an JAXB Class instance, containing this field declaration is marshalled:
@xmlelement(name = "NillableElement1", nillable = true)
protected String nillableElement1;
And the field (nillableElement1) contains null, the resulting XML will ALWAYS generate a NILL reference:
Even though the two XML schema examples above are semantically identical, they cause different JAXB Binding to be generated, one of which (Example 2) has two major problems:
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use JAXB to generate binding classes of a schema (attached: sample.xsd)
Look at the resulting OptionalNillable.java class (attached).
See the difference between the nillableElement1 and nillableElement2 fields of the OptionalNillable.java class.
Full maven project with unit tests can be provided, upon request.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Given the XML schema declarations...
The resulting JAXB binding fields for NillableElement1 and NillableElement2 should both be of type JAXBElement, like:
ACTUAL -
NillableElement1 is declared as a String:
ERROR MESSAGES/STACK TRACES THAT OCCUR :
(none)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
File: sample.xsd
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:jaxb:sample" targetNamespace="urn:jaxb:sample" elementFormDefault="qualified">
</xsd:schema>
File: OptionalNillable.java
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4
// See http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2011.10.28 at 10:22:00 AM CEST
//
package jaxb.sample;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.jvnet.jaxb2_commons.lang.Equals;
import org.jvnet.jaxb2_commons.lang.EqualsStrategy;
import org.jvnet.jaxb2_commons.lang.HashCode;
import org.jvnet.jaxb2_commons.lang.HashCodeStrategy;
import org.jvnet.jaxb2_commons.lang.JAXBEqualsStrategy;
import org.jvnet.jaxb2_commons.lang.JAXBHashCodeStrategy;
import org.jvnet.jaxb2_commons.lang.JAXBToStringStrategy;
import org.jvnet.jaxb2_commons.lang.ToString;
import org.jvnet.jaxb2_commons.lang.ToStringStrategy;
import org.jvnet.jaxb2_commons.locator.ObjectLocator;
import org.jvnet.jaxb2_commons.locator.util.LocatorUtils;
/**
Java class for anonymous complex type.
The following schema fragment specifies the expected content contained within this class.
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"nillableElement1",
"nillableElement2"
})
@XmlRootElement(name = "OptionalNillable")
public class OptionalNillable
implements Equals, HashCode, ToString
{
}
---------- END SOURCE ----------
The text was updated successfully, but these errors were encountered: