1.2.1.1. XML Object Serialization Example

Data Instance. 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<anExampleDataClass>
    <anIntField>123</anIntField>
    <aFloatField>12.34</aFloatField>
    <aDoubleField>1.234E57</aDoubleField>
    <aBoxedIntField>987</aBoxedIntField>

    <aRequiredStringField>a string</aRequiredStringField>
    <anArrayWithoutAWrapper>1</anArrayWithoutAWrapper>
    <anArrayWithoutAWrapper>2</anArrayWithoutAWrapper>
    <anArrayWithoutAWrapper>3</anArrayWithoutAWrapper>

    <anArrayWithAWrapper>
        <anArrayElement>12</anArrayElement>
        <anArrayElement>34</anArrayElement>
        <anArrayElement>56</anArrayElement>
    </anArrayWithAWrapper>

    <aListElement>
        <anIntField>0</anIntField>
        <aFloatField>0.0</aFloatField>
        <aDoubleField>0.0</aDoubleField>
    </aListElement>

    <aSetElement>
        <anIntField>0</anIntField>
        <aFloatField>0.0</aFloatField>
        <aDoubleField>0.0</aDoubleField>
    </aSetElement>

    <aMapElement>
        <entry>
            <key>456</key>
            <value>
                <anIntField>0</anIntField>
                <aFloatField>0.0</aFloatField>
                <aDoubleField>0.0</aDoubleField>
            </value>
        </entry>
        <entry>
            <key>123</key>
            <value>
                <anIntField>0</anIntField>
                <aFloatField>0.0</aFloatField>
                <aDoubleField>0.0</aDoubleField>
            </value>
        </entry>
    </aMapElement>
</anExampleDataClass>

Possible Schema. 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0">

    <xs:element name="anExampleDataClass" type="anExampleDataClass"/>

    <xs:complexType name="anExampleDataClass">
        <xs:annotation>
            <xs:documentation>
                An example class.
                Contains various field types to illustrate the mapping.
            </xs:documentation>
        </xs:annotation>

        <xs:all>
            <xs:element name="anIntField" type="xs:int"/>
            <xs:element name="aFloatField" type="xs:float"/>
            <xs:element name="aDoubleField" type="xs:double"/>

            <xs:element minOccurs="0" name="aBoxedIntField" type="xs:int"/>
            <xs:element name="aRequiredStringField" type="xs:string"/>
            <xs:element minOccurs="0" name="anOptionalStringField" type="xs:string"/>
            <xs:element default="default" minOccurs="0" name="aStringFieldWithDefaultValue" type="xs:string"/>

            <xs:element maxOccurs="unbounded" minOccurs="0" name="anArrayWithoutAWrapper" type="xs:int"/>
            <xs:element minOccurs="0" name="anArrayWithAWrapper">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element maxOccurs="unbounded" minOccurs="0" name="anArrayElement" type="xs:int"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>

            <xs:element maxOccurs="unbounded" minOccurs="0" name="aListElement" type="anExampleDataClass"/>
            <xs:element maxOccurs="unbounded" minOccurs="0" name="aSetElement" type="anExampleDataClass"/>

            <xs:element name="aMapElement">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element maxOccurs="unbounded" minOccurs="0" name="entry">
                            <xs:complexType>
                                <xs:sequence>
                                    <xs:element minOccurs="0" name="key" type="xs:int"/>
                                    <xs:element minOccurs="0" name="value" type="anExampleDataClass"/>
                                </xs:sequence>
                            </xs:complexType>
                        </xs:element>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:all>
    </xs:complexType>
</xs:schema>