You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Sergey Beryozkin <sb...@gmail.com> on 2011/07/01 11:11:12 UTC

Re: Illegal JSONP in the response when requesting strings

Hi Carl-Erik

On Thu, Jun 30, 2011 at 1:57 PM, Carl-Erik Kopseng <ca...@gmail.com> wrote:
> According to the JSON spec, legal values are
>    string
>    number
>    object
>    array
>    true
>    false
>    null
>
> "A string is a sequence of zero or more Unicode characters, wrapped in
> double quotes, using backslash escapes."
>
> Therefore, when I have a service such as the following, calling it as
> /retrieveText?_jsonp=myCallBack, I expect it to return
> myCallBack("Hello, world")
>
>        @GET
>        @Path("retrieveText")
>        @Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN})
>        public String retrieveText() {
>                        return "Hello, world";
>        }
>
> Unfortunately, it just returns myCallBack(Hello, world), which is
> something else completely, when evaluted by the javascript
> interpreter.
>
> My take on this is that the json messagebody reader should really be
> spitting out quoted strings in the content body. That would both make
> the value legal and the jsonp work as expected. Any takes on how I can
> fix this now, before the bug is fixed? I do not want to add escaped
> double quotes to the returned string, as that would affect all content
> types, not just json(p).
>

Default (OTB) JSONProvider is JAXB-driven thus it does not understand
top-level primitive/String objects.
Try registering Jackson as a provider - may be it can handle top-level Strings

Cheers, Sergey

> --
> Carl-Erik Kopseng
>
> (+47) 40065078
> skype: carl.erik.kopseng
> blogg: oligofren.wordpress.com
> ##########################
> Ser ikke skogen for bare syntakstrær
>