Skip to main content

XML Methodology

The following examples show how different data types are represented in XML. They mirror how the data structures are represented in JSON.

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/>
Maps

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).

Data typeJSON exampleXML
Map
{
k1: 'v1',
k2: null
}
<object>
<k1>v1</k1>
<k2 _type='null'/>
</object>
Map
{
k1: 123,
k2: 1.23,
k3: null
}
<object>
<k1>123</k1>
<k2>1.23</k2>
<k3 _type='null'/>
</object>
Map
{
k1: 'v1',
k2: 123,
k3: 1.23,
k4: true,
k5: null
}
<object>
<k1>v1</k1>
<k2 _type='number'>123</k2>
<k3 _type='number'>1.23</k3>
<k4 _type='boolean'>true</k4>
<k5 _type='null'/>
</object>
Arrays

Loose collections and arrays use the element <array> for encapsulation.

Data typeJSON exampleXML
String[]
['foo', null]
<array>
<string>foo</string>
<null/>
</array>
Number[]
[123, 1.23, null]
<array>
<number>123</number>
<number>1.23</number>
<null/>
</array>
Object[]
['foo', 123, 1.23, true, null]
<array>
<string>foo</string>
<number>123</number>
<number>1.23</number>
<boolean>true</boolean>
<null/>
</array>
String[][]
[['foo', null], null]
<array>
<array>
<string>foo</string>
<null/>
</array>
<null/>
</array>
int[]
[123]
<array>
<number>123</number>
</array>
boolean[]
[true]
<array>
<boolean>true</boolean>
</array>
List<String>
['foo', null]
<array>
<string>foo</string>
<null/>
</array>
List<Number>
[123, 1.23, null]
<array>
<number>123</number>
<number>1.23</number>
<null/>
</array>
List<Object>
['foo', 123, 1.23, true, null]
<array>
<string>foo</string>
<number>123</number>
<number>1.23</number>
<boolean>true</boolean>
<null/>
</array>
Beans
Data typeJSON exampleXML
class MyBean {
public String a;
public int b;
public Object c; // String value
public Object d; // Integer value
public MyBean2 e;
public String[] f;
public int[] g;
}

class MyBean2 {
String h;
}
{
a: 'foo',
b: 123,
c: 'bar',
d: 456,
e: {
h: 'baz'
},
f: ['qux'],
g: [789]
}
<object>
<a>foo</a>
<b>123</b>
<c>bar</c>
<d _type='number'>456</d>
<e>
<h>baz</h>
</e>
<f>
<string>qux</string>
</f>
<g>
<number>789</number>
</g>
</object>
Beans with Map properties
Data typeJSON exampleXML
class MyBean {
public Map<String,String> a;
public Map<String,Number> b;
public Map<String,Object> c;
}
{
a: { k1: 'foo' },
b: { k2: 123 },
c: {
k3: 'bar',
k4: 456,
k5: true,
k6: null
}
}
<object>
<a>
<k1>foo</k1>
</a>
<b>
<k2>123</k2>
</b>
<c>
<k3>bar</k3>
<k4 _type='number'>456</k4>
<k5 _type='boolean'>true</k5>
<k6 _type='null'/>
</c>
</object>