Ok, thank you Sergey.

Well, it could be welcome to describe the JSONP activation "side effect" in the 
CXF documentation :)

JP

-----Message d'origine-----
De : Sergey Beryozkin [mailto:[email protected]] 
Envoyé : lundi 18 juillet 2016 18:27
À : [email protected]
Cc : CLEMENT Jean-Philippe
Objet : Re: JSON -> JSONP leads to "No message body writer has been found for 
class"

Hi

I replied to your earlier message, see

http://cxf.547215.n5.nabble.com/JSONP-No-message-body-writer-has-been-found-for-class-tp5770477p5770482.html

Some comments inline:

On 18/07/16 19:09, CLEMENT Jean-Philippe wrote:
> I found a workaround. As far as I understood the JSONP stuff tries to 
> serialize my sample object as "application/x-javascript" (instead of 
> "application/json"), which is not recognized by the default provider.
>
> So I changed the JSONProvider "produceMediaTypes" with 
> "application/x-javascript" as well as "application/json". Which works, but I 
> don't catch why I have to do so.

To make the default provider recognize "application/x-javascript" :-).


> Also it seems the JSonpInInterceptor has a property to change the content 
> type output, but it still outputs "application/x-javascript".

It's been awhile since I looked at this code - but I've checked now, this 
mediaType property has something to do with selecting the callback value. I may 
need to refresh it a bit and update the docs.

By the way re 2nd option described in my other email, where 'accept' 
property is set - without it, with Jackson present, it is impossible to select 
Jackson (at least it was the case when I looked at it last time) as it does not 
recognize JSONP media type.
>
> Is it the most simple way to obtain a JSONP output?
>
Well, in my experience and as I explained above some tuning needs to be done 
for the 2 providers (default one and Jackson) work with JSONP.

I might need to revisit those tests and see if the providers are behaving 
differently know

Sergey

> PS: It would be so nice to have a simple option or annotation to 
> output via JSONP :)
>
> Regards,
> Jean-Philippe
>
> -----Message d'origine-----
> De : CLEMENT Jean-Philippe 
> [mailto:[email protected]]
> Envoyé : lundi 18 juillet 2016 16:38
> À : [email protected]
> Objet : JSONP -> No message body writer has been found for class
>
> Dear CXF users,
>
> I'm new to CXF and I'm writing a kind of "hello world" JAX-RS service which 
> works well with the default JSON output. Following the user doc, I added 
> interceptors to allow JSONP output.
>
> JSONP messages now contain the callback method name but its message content 
> is "No message body writer has been found for class...". This is strange as 
> if I remove the interceptors, the JSON output is correct (the message content 
> is serialized properly).
>
> I tried to set the provider to 
> "org.apache.cxf.jaxrs.provider.json.JSONProvider" but with no success (same 
> output). What's wrong?
>
> Regards,
> Jean-Philippe
>


--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Reply via email to