I have the following java object
class MyXmlObject{
@JsonProperty
private InnerObject innerObject;
@JsonProperty
private String someOtherProperty;
}
When I serialize this using
public String getXmlObjectAsXML(MyXmlObject myXmlObject){
JacksonXmlModule module = new JacksonXmlModule();
module.setDefaultUseWrapper(false);
XmlMapper mapper = new XmlMapper(module);
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
String response = "";
response = mapper.writeValueAsString(myXmlObject);
return response;
}
I would like the InnerObject class to be wrapped in a CDATA tag.
What is the correct way to handle this scenario?
Syntax. CDATA End section − CDATA section ends with ]]> delimiter. CData section − Characters between these two enclosures are interpreted as characters, and not as markup. This section may contain markup characters (<, >, and &), but they are ignored by the XML processor.
A CDATA section is used to mark a section of an XML document, so that the XML parser interprets it only as character data, and not as markup. It comes handy when one XML data need to be embedded within another XML document.
CDATA sections can appear inside element content and allow < and & character literals to appear. A CDATA section begins with the character sequence <! [CDATA[ and ends with the character sequence ]]>. Between the two character sequences, an XML processor ignores all markup characters such as <, >, and &.
The only sequence which is not allowed within a CDATA section is the closing sequence of a CDATA section itself, ]]> .
There is @JacksonXmlCData
since 2.5. https://github.com/FasterXML/jackson-dataformat-xml:
@JacksonXmlCData
allows specifying that the value of a property is to be serialized within a CData tag.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With