Skip to main content

@Xml Collapsed Format

The XmlFormat.COLLAPSED format can be applied to bean properties of type array/Collection. This causes the child objects to be serialized directly inside the bean element. This format must be used in conjunction with @Xml(childName) to differentiate which collection the values came from if you plan on parsing the output back into beans. Note that child names must not conflict with other property names.

Data typeJSON exampleWithout annotationWith annotation
class MyBean {
@Xml(childName="A",format=XmlFormat.COLLAPSED)
public String[] a;
@Xml(childName="B",format=XmlFormat.COLLAPSED)
public int[] b;
}
{
a: ['foo','bar'],
b: [123,456]
}
<object>
<a>
<string>foo</string>
<string>bar</string>
</a>
<b>
<number>123</number>
<number>456</number>
</b>
</object>
<object>
<A>foo</A>
<A>bar</A>
<B>123</B>
<B>456</B>
</object>

See also​