@Xml Attribute Formats
The attribute-oriented XmlFormat values move bean-property values between XML attributes and child elements:
- XmlFormat.ATTR promotes a single property to an attribute.
- XmlFormat.ATTRS makes a whole bean render its properties as attributes, or lets a single
Mapproperty contribute arbitrary attributes. - XmlFormat.ELEMENT forces a property back to a child element, overriding an
ATTRSdefault applied to the class.
Rendering a property as an attribute — ATTR
The XmlFormat.ATTR format can be applied to bean properties to serialize them as XML attributes instead of elements. Note that this only supports properties of simple types (e.g. strings, numbers, booleans).
| Data type | JSON example | Without annotation | With annotation |
|---|---|---|---|
| | | |
Rendering all properties as attributes — ATTRS
The XmlFormat.ATTRS format can be applied to bean classes to force all bean properties to be serialized as XML attributes instead of child elements.
| Data type | JSON example | Without annotation | With annotation |
|---|---|---|---|
| | | |
Overriding the class default — ELEMENT
The XmlFormat.ELEMENT format can be applied to bean properties to override the XmlFormat.ATTRS format applied on the bean class.
| Data type | JSON example | Without annotation | With annotation |
|---|---|---|---|
| | | |
Arbitrary attributes from a Map — ATTRS
The XmlFormat.ATTRS format can also be applied to a
single bean property of type Map to denote arbitrary XML attribute values on the element.
These can be mixed with other XmlFormat.ATTR
annotated properties but there must not be an overlap in bean property names and map keys.
| Data type | JSON example | Without annotation | With annotation |
|---|---|---|---|
| | | |
See also
- @Xml(format) Annotation for the full list of
XmlFormatvalues. - Collapsed Format for flattening arrays and collections.