The WSIT Tutorial

List of Nillable Elements

Guideline: By default, a collection type such as List<Integer> maps to an XML schema construct that is a repeating unbounded occurrence of an optional and nillable element. .NET binds the XML schema construct to System.Nullable<int>[]. The element is optional and nillable. However, when marshalling JAXB marshaller will always marshal a null value using xsi:nil.

Example: Collection to a list of nillable elements

//-- Java code fragment
public PurchaseOrder {
    public List<Integer> items;

//-- Schema fragment
<xs:element name="po" type="purchaseOrder">
<xs:complexType name="purchaseOrder">
        <xs:element name="items" type="xs:int" nillable="true"
                    minOccurs="0" maxOccurs="unbounded"/>

//--- JAXB XML serialization
    <items> 1 </items>
    <items> 2 </items>
    <items> 3 </items>

    <items> 1 </items>
    <items xsi:nil=true/>
    <items> 3 </items>

//-- .NET auto generated code from schema
partial class purchaseOrder {
        private System.Nullable<int>[] itemsField;

    public System.Nullable<int>[] items
        get { return this.itemsField; }
        set { this.itemsField = value; }