dev@jersey.java.net

Re: [Jersey] JSONP wrapper for Jackson (JSONPObject.java)

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 10 Feb 2010 14:51:00 +0100

On Feb 10, 2010, at 8:46 AM, Tatu Saloranta wrote:

> --- On Mon, 2/8/10, Paul Sandoz <Paul.Sandoz_at_Sun.COM> wrote:
>
>> From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
>> Subject: Re: [Jersey] JSONP wrapper for Jackson (JSONPObject.java)
>> To: dev_at_jersey.dev.java.net
>> Cc: dev_at_jackson.codehaus.org
>> Date: Monday, February 8, 2010, 5:31 AM
>> Hi Tatu,
>>
>> Do you have a link to the source of:
>>
>> org.codehaus.jackson.map.util.JSONPObject
>
> Sure, let's see... here:
>
> http://fisheye.codehaus.org/browse/jackson/trunk/src/mapper/java/org/codehaus/jackson/map/util/JSONPObject.java?r=HEAD
>
>> Do you know if we can retain backwards compatibility with
>> Jersey's JSONWthPadding class by leveraging JSONPObject? For
>> example, if the Jackson JAX-RS providers are registered
>> Jackson JSON with padding will be utilized, otherwise
>> fallback to the Jersey approach will be utilized.
>
> I am not familiar with integration code, but since wrapper can be
> easily added as needed (as long as caller knows who receives it),
> and 'peeled off' too, I would think so.
>
>> Jersey's JSONWthPadding is a bit special because JSON with
>> padding is only used if an appropriate media type is
>> acceptable i.e. it could be used with say application/xml,
>> application/json or say application/javascript and only the
>> latter will result in padding.
>
> Right. Wrapper I added has no extra logic, so whoever adds that
> needs to make the decision to use it or not.
>

OK. Jakub is on the case and will integrate.


>> Also can the Jackson processing escape JSON text (that
>> might be say HTML content)?
>
> No. I have not used JSONP myself, so I did not know if there are
> fancier usage patterns (beyond simple method names -- I know that it
> could be any legal javascript expression). Sounds like there are. :-)
>

I am trying to find out more information but i have seen HTML embedded
in the JSON and that needed to be escaped, but i cannot recall why.
Jean Francois did some JSONP with embedded HTML and escaping in some
Atmsophere samples so may be able to shed some light on this matter.


> Wrapper does use Jackson's "raw" write methods to bypass all quoting/
> escaping, so caller can pre-encode assumed function name, although
> parentheses are always added. But that should be safe wrt javascript
> expression (value in parenthesis is same as without).
>

OK.

Paul.