@Xml Element & Mixed Formats
The element-oriented XmlFormat values let a single property produce free-form or mixed child content:
- XmlFormat.FREEFORM emits child elements for the property value.
- XmlFormat.MIXED and XmlFormat.MIXED_PWS produce mixed content by stripping element names from primitive values.
Free-form child elements — FREEFORM
The XmlFormat.FREEFORM format can be applied to
a single bean property of either a simple type or array/Collection.
It allows free-form child elements to be formed.
All other properties on the bean MUST be serialized as attributes.
| Data type | JSON example | With annotation |
|---|---|---|
| | |
| | |
Mixed content — MIXED and MIXED_PWS
The XmlFormat.MIXED format is similar to XmlFormat.FREEFORM except elements names on primitive types (string/number/boolean/null) are stripped from the output. This format particularly useful when combined with bean dictionaries to produce mixed content. The bean dictionary isn't used during serialization, but it is needed during parsing to resolve bean types. The XmlFormat.MIXED_PWS format identical to XmlFormat.MIXED except whitespace characters are preserved in the output.
| Data type | JSON example | Without annotations | With annotations |
|---|---|---|---|
| | | |
It should be noted that when using MIXED, you are not guaranteed to parse back the exact same content since side-by-side strings in the content will end up concatenated when parsed.
For a detailed treatment of how empty strings and whitespace are preserved (or lost) in MIXED and MIXED_PWS output,
see Whitespace Handling.
See also
- @Xml(format) Annotation for the full list of
XmlFormatvalues. - Text Formats for
TEXT,TEXT_PWS, andXMLTEXT. - Whitespace Handling for the whitespace rules that apply to mixed content.