Skip to main content

XML Methodology

This page describes how the different POJO datatypes are represented in XML. The representations mirror how the same data structures are represented in JSON:

  • Simple values (strings, numbers, booleans, nulls) render as elements named after their datatype (<string>, <number>, <boolean>, <null/>) when loose (not a direct bean property value).
  • Maps and beans render inside <object> elements.
  • Collections and arrays render inside <array> elements.

The examples below show one representative case per category. For the complete set of data-type representations (all Map, array, Collection, and bean shapes), see the reference tables on the XML Serializers page.

Simple types​

The representation of loose (not a direct bean property value) simple types are shown below:

Data typeJSON exampleXML
string
'foo'
<string>foo</string>
boolean
true
<boolean>true</boolean>
integer
123
<number>123</number>
float
1.23
<number>1.23</number>
null
null
<null/>

Objects​

Loose maps and beans use the element <object> for encapsulation. _type attributes are added to bean properties or map entries if the type cannot be inferred through reflection (e.g. an Object or superclass/interface value type).

The following representative example shows a bean containing simple values, a value whose type must be tagged, a nested bean, and array properties:

Data typeJSON exampleXML
class MyBean {
public String a;
public int b;
public Object c; // Integer value
public MyBean2 d;
public int[] e;
}

class MyBean2 {
String h;
}
{
a: 'foo',
b: 123,
c: 456,
d: {
h: 'baz'
},
e: [789]
}
<object>
<a>foo</a>
<b>123</b>
<c _type='number'>456</c>
<d>
<h>baz</h>
</d>
<e>
<number>789</number>
</e>
</object>

Arrays and collections​

Loose collections and arrays use the element <array> for encapsulation. Collections (e.g. List, Set) serialize identically to their array equivalents.

The following representative example shows a mixed-type Object[]:

Data typeJSON exampleXML
Object[]
['foo', 123, 1.23, true, null]
<array>
<string>foo</string>
<number>123</number>
<number>1.23</number>
<boolean>true</boolean>
<null/>
</array>