You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by CLEMENT Jean-Philippe <je...@fr.thalesgroup.com> on 2016/07/18 16:09:32 UTC
JSON -> JSONP leads to "No message body writer has been found for
class"
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. Also it seems the JSonpInInterceptor has a property to change the content type output, but it still outputs "application/x-javascript".
Is it the most simple way to obtain a JSONP output?
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:jean-philippe.clement@fr.thalesgroup.com]
Envoyé : lundi 18 juillet 2016 16:38
À : users@cxf.apache.org
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
RE: JSON -> JSONP leads to "No message body writer has been found
for class"
Posted by CLEMENT Jean-Philippe <je...@fr.thalesgroup.com>.
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:sberyozkin@gmail.com]
Envoyé : lundi 18 juillet 2016 18:27
À : users@cxf.apache.org
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:jean-philippe.clement@fr.thalesgroup.com]
> Envoyé : lundi 18 juillet 2016 16:38
> À : users@cxf.apache.org
> 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/
Re: JSON -> JSONP leads to "No message body writer has been found for
class"
Posted by Sergey Beryozkin <sb...@gmail.com>.
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:jean-philippe.clement@fr.thalesgroup.com]
> Envoy : lundi 18 juillet 2016 16:38
> : users@cxf.apache.org
> 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/