Class XmlSerializer

All Implemented Interfaces:
AnnotationProvider, XmlMetaProvider
Direct Known Subclasses:
HtmlSerializer, SoapXmlSerializer, XmlDocSerializer, XmlSerializer.Ns, XmlSerializer.NsSq, XmlSerializer.NsSqReadable, XmlSerializer.Sq, XmlSerializer.SqReadable

public class XmlSerializer extends WriterSerializer implements XmlMetaProvider
Serializes POJO models to XML.
Media types

Handles Accept types: text/xml

Produces Content-Type types: text/xml

Description

See the JsonSerializer class for details on how Java models map to JSON.

For example, the following JSON...

{ name:'John Smith', address: { streetAddress: '21 2nd Street', city: 'New York', state: 'NY', postalCode: 10021 }, phoneNumbers: [ '212 555-1111', '212 555-2222' ], additionalInfo: null, remote: false, height: 62.4, 'fico score': ' > 640' }

...maps to the following XML using the default serializer...

<object> <name>John Smith</name> <address> <streetAddress>21 2nd Street</streetAddress> <city>New York</city> <state>NY</state> <postalCode>10021</postalCode> </address> <phoneNumbers> <string>212 555-1111</string> <string>212 555-2222</string> </phoneNumbers> <additionalInfo _type='null'></additionalInfo> <remote>false</remote> <height>62.4</height> <fico_x0020_score> &gt; 640</fico_x0020_score> </object>

An additional "add-json-properties" mode is also provided to prevent loss of JSON data types...

<object> <name _type='string'>John Smith</name> <address _type='object'> <streetAddress _type='string'>21 2nd Street</streetAddress> <city _type='string'>New York</city> <state _type='string'>NY</state> <postalCode _type='number'>10021</postalCode> </address> <phoneNumbers _type='array'> <string>212 555-1111</string> <string>212 555-2222</string> </phoneNumbers> <additionalInfo _type='null'></additionalInfo> <remote _type='boolean'>false</remote> <height _type='number'>62.4</height> <fico_x0020_score _type='string'> &gt; 640</fico_x0020_score> </object>

This serializer provides several serialization options. Typically, one of the predefined DEFAULT serializers will be sufficient. However, custom serializers can be constructed to fine-tune behavior.

If an attribute name contains any non-valid XML element characters, they will be escaped using standard _x####_ notation.

Behavior-specific subclasses

The following direct subclasses are provided for convenience:

Notes:
  • This class is thread safe and reusable.
See Also: