The WSIT Tutorial

Default Binding

The following is the default binding of an optional (minOccurs="0") and nillable(nillable="true") element:

//-- XML schema fragment
<xs:element name="person" type="Person"
<xs:complexType name="Person">
        <xs:element name="name" type="xs:string" 
                    nillable="true" minOccurs="0"/>

// Binding
public class Person {
    JAXBElement<String> getName() {...};
    public void setName(JAXBElement<String> value) {...}

Since the XML element name is both optional and nillable, it can be represented in an XML instance in one of following ways:

<!-- Absence of element name-->
    <-- element name is absent -->

<!-- Presence of an element name -->
    <name xsi:nil="true"/>

The JAXBElement<String> type roundtrips the XML representation of name element across an unmarshal/marshal operation.