users@jersey.java.net

Re: [Jersey] JSONP

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 20 Jan 2010 18:27:45 +0000

On Jan 20, 2010, at 5:46 PM, Jakub Podlesak wrote:

>
> Hi Ben,
>
> Now i know what is going wrong in this case.
> You do not get any exception nor error, but just a wrong
> strange JSON data back, right?
>
> JSONWithPadding is accompanied with it's own JSON writer.
> But this writer is never picked up, as the Jackson one takes
> precedence.
>
> Please confirm this is the behavior you are experiencing,
> i.e. instead of e.g. {"one":"apple", "two":"onion"},
> which represents the map, you getting st. like:
>
> {"jsonSource":{"one":"apple", "two":"onion"},
> "callbackName","callback"}
>

JSONWithPadding writing is triggered for the following media types:

         javascriptTypes.put("application", new
HashSet<String>(Arrays.asList("x-javascript", "ecmascript",
"javascript")));
         javascriptTypes.put("text", new
HashSet<String>(Arrays.asList("ecmascript", "jscript")));

So if one of those is more acceptable than application/json then you
will get JavaScript back with JSON embedded in a function.

Paul.


> Right?
>
> ~Jakub
>
>
> On Wed, Jan 20, 2010 at 05:01:41PM +0100, Jakub Podlesak wrote:
>> On Wed, Jan 20, 2010 at 10:16:04AM -0500, Ben Darfler wrote:
>>> Forgive this question as it might not make sense yet but I'm
>>> trying to
>>> wade through this.
>>
>> No problem, your question makes perfect sense.
>>
>>>
>>> I'm currently using jackson as the json provider for jersey. We have
>>> an interest in supporting JSONP and I'm wondering if there is a
>>> way to
>>> do this. I've found JSONWithPadding class in Jersey that seems to
>>
>> The JSONWithPaddingWrapper is exactly what you need.
>>
>>> suggest a way of doing this but I'm not sure of the syntax.
>>> Previous I
>>> would just return a map from my restful method and jackson/jersey
>>> would take care of the serialization. However, if I change the
>>> method
>>> to return new JSONWithPadding(map) it fails and I'm not easily
>>> able to
>>> figure out why. My gut says that I need to add JAXB annotations to
>>> my
>>
>> From your description it seems, you use the wrapper the way it was
>> intended.
>> There should be no need for any extra annotations. What kind of
>> failure are you getting?
>> Any exception stack trace?
>>
>>> objects which I have been able to avoid so far. Is there any way of
>>> doing jsonp with jackson as the json provider for jersey? (whew
>>> thats
>>
>> It is possible that you revealed a bug in the JSONP support in
>> Jersey,
>> what kind of map do you use? I need to add a test for this, as so far
>> only the JAXB based scenario has been tested.
>>
>>> a lot of buzz words).
>>>
>>> I asked the jackson mailer and they are interested in helping out on
>>> this if anything needs to be done on their side.
>>
>> Thanks for the info, i will contact Tatu, if there is a need.
>>
>> ~Jakub
>>
>>>
>>> http://archive.codehaus.org/lists/org.codehaus.jackson.user/msg/5f7770581001191408m3659e3e4w608b294ce6041947@mail.gmail.com
>>>
>>> Ben
>>>
>>>
>>> --
>>> Software Engineer
>>> LocaModa
>>> Connecting People & Places
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>
>>
>> --
>> http://blogs.sun.com/japod
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
> --
> http://blogs.sun.com/japod
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>