Skip to main content

@Xml Text Formats

The text-oriented XmlFormat values render a single property value directly as the character content of the element:

Text content — TEXT and TEXT_PWS​

The XmlFormat.TEXT format is similar to XmlFormat.MIXED except it's meant for solitary objects that get serialized as simple child text nodes. Any object that can be serialize to a String can be used. The XmlFormat.TEXT_PWS is the same except whitespace is preserved in the output.

Data typeJSON exampleWithout annotationsWith annotations
class MyBean {
@Xml(format=XmlFormat.TEXT)
public String a;
}
{
a: 'foo'
}
<object>
<a>foo</a>
</object>
<object>
foo
</object>

Embedded XML content — XMLTEXT​

The XmlFormat.XMLTEXT format is similar to XmlFormat.TEXT except it's meant for strings containing XML that should be serialized as-is to the document. Any object that can be serialize to a String can be used. During parsing, the element content gets parsed with the rest of the document and then re-serialized to XML before being set as the property value. This process may not be perfect (e.g. double quotes may be replaced by single quotes, etc...).

Data typeJSON exampleWith TEXT annotationWith XMLTEXT annotation
class MyBean {
@Xml(format=XmlFormat.XMLTEXT)
public String a;
}
{
a: 'Some <b>XML</b> text'
}
<object>
Some &lt;b&gt;XML&lt;/b&gt; text
</object>
<object>
Some <b>XML</b> text
</object>

See also​