0

I have a project using a 3rd party lib, including generated JAXB Java objects (Which I haven no source control over)

I found that one of the elements in this model, expects a <![CDATA blob. Is there any way to make Jaxb marshaller aware of this, and not escape the output in that particular field?

The XML model is as follows:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(
    name = "MyComplexType",
    propOrder = {"val1", "cdataval"}
)
public class MyComplexType {
    @XmlElement(
        name = "val1",
        required = true
    )
    protected String val1;

    protected String cdataval;

    public MyComplexType() {
    }

    ... getter and setters...
}

So, as I mentioned earlier, adding CData to the cdataval makes JaxB marshaller escape the content leading to invalid CData content.

How could I make the marshaller NOT escape the content, without modifying the generated sources? It would be so easy to just add a special XmlAdapter on that field, but nope, can't do that.

Regards

Robin Jonsson
  • 2,761
  • 3
  • 22
  • 42

0 Answers0