users@jersey.java.net

Re: [Jersey] Marshalling CDATA with JAXB

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 10 Aug 2009 10:00:06 +0200

On Aug 10, 2009, at 9:39 AM, Julian Reschke wrote:

> MS wrote:
>> Hi,
>> I have another question related to JAXB and Jersey. I would like to
>> return an XML representation that contains CDATA, but apparently
>> JAXB can't deal with it correctly. There is a FAQ entry on the JAXB
>> page: https://jaxb.dev.java.net/faq/index.html#marshalling_cdata
>> The XML content in the http request looks like this:
>> <myXml>
>> <tagWithCdata><![CDATA[<test>123</test>]]></tagWithCdata>
>> </myXml>
>> The String "tagWithCdata" in the Java object like this: "<test>123</
>> test>"
>> And the marshalled XML in the http response like this:
>> <myXml>
>> <tagWithCdata>&lt;test&gt;123&lt;/test&gt;</tagWithCdata>
>> </myXml>
>> Does anyone have an idea what is the best way to get a response
>> that looks like the request and includes CDATA?
>> Thanks a lot!
>> ...
>
> Why do you care? The difference shouldn't matter in practice; these
> are just two different ways of escaping the same information.
>

Good point. CDATA makes it easier for humans to edit XML documents.

I suppose one can also consider it an optimization to reduce the size
of XML documents that would otherwise contain lots of &-escaped
characters. But GZIP is a good solution too.

Paul.