Hi Arul,
Unfortunately this is a restriction in default JAXB marshaling, which
Jersey uses [1].
To support this you will need to do your own marshalling using say the
Apache XMLSerializer [2]. But in this case it is trickier to do anything
generic using MessageBodyWriter because specific CDATA elements need to
be explicitly referred to when using the Apache XMLSerializer.
Arul Dhesiaseelan wrote:
> Hi,
>
> My REST method returns @ProduceMime({"application/xml"}). Inside the
> method, I am using JAXB to construct the XML response. One of the nodes
> in the XML has an embedded CDATA string.
> When I invoke this method, I do not see the CDATA entities properly
> encoded. I see <, >, " instead of <, >, ". I see the browser
> can handle this response just fine. But, the consumer of this method is
> a different application.
>
> Is there a way to configure this in the REST method? Or, do we need to
> have this decoding logic in the consumer?
>
It should not matter from the perspective of parsing the document using
an XML parser as the text content is semantically the same.
CDATA is an encoding optimization (both encoding/decoding performance
and document size) and also a human writing optimization for those that
wish to write XML documents by hand.
From [3]:
In an XML document or external parsed entity, a CDATA section is a
section of element content that is marked for the parser to interpret
as only character data, not markup. A CDATA section is merely an
alternative syntax for expressing character data; there is no semantic
difference between character data that manifests as a CDATA section
and character data that manifests as in the usual syntax in which "<"
and "&" would be represented by "<" and "&", respectively.
Paul.
[1]
https://jaxb.dev.java.net/faq/index.html#marshalling_cdata
[2]
https://jaxb.dev.java.net/faq/JaxbCDATASample.java
[3]
http://en.wikipedia.org/wiki/CDATA
> Please advice.
>
> Thanks!
> Arul
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
--
| ? + ? = To question
----------------\
Paul Sandoz
x38109
+33-4-76188109