users@jersey.java.net

Re: [Jersey] Marshalling CDATA with JAXB

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

On Aug 10, 2009, at 9:12 AM, MS wrote:

> MS schrieb:
>> Felipe Gaścho schrieb:
>>> https://jaxb.dev.java.net/faq/JaxbCDATASample.java
>>>
>> I am not sure how to integrate this approach in my Jersey
>> application.
>>
>> Can I use a ContextResolver that provides the marshalled object?
>> And if yes, what type should it return?
>>
>> Or do I have to write a new MessageBodyWriter?
> I digged into the source code and found the
> com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider that
> can be extended to customize the marshalling behaviour. So I tried
> to extend it, but now I am struggling to register it as a provider.
> I am using Jersey with Spring and I do not know how to register a
> provider as a Spring bean that does not have a default constructor
> (like the AbstractRootElementProvider).
>

Constructor injection is always tricky to integrate. We do not have
Spring integration such that it knows about how to inject the Provider
interface.

The only solution i can suggest is to not make your implementation a
Spring managed bean and let Jersey manage it. If you need access to
Spring managed stuff you can inject that stuff in using the @Inject
annotation:

   https://jersey.dev.java.net/nonav/apidocs/1.1.1-ea/jersey/com/sun/jersey/spi/inject/Inject.html

However, i am not sure you need to extend this class. You should be
able to use ContextResolver<Marshaller>.


> Are there any examples that show how to extend an abstract provider
> and make sure that it is called instead of the default one?
>

No currently, only that for XML and JSON in the code itself :-(

Paul.

>>
>>> perhaps URL Decode works as well
>>>
>>> On Sun, Aug 9, 2009 at 10:01 PM, MS<da_bus_at_arcor.de> 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!
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>