dev@jersey.java.net

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

From: Tatu Saloranta <cowtowncoder_at_yahoo.com>
Date: Tue, 9 Feb 2010 23:46:40 -0800 (PST)

--- On Mon, 2/8/10, Paul Sandoz <Paul.Sandoz@Sun.COM> wrote: > From: Paul Sandoz <Paul.Sandoz@Sun.COM> > Subject: Re: [Jersey] JSONP wrapper for Jackson (JSONPObject.java) > To: dev@jersey.dev.java.net > Cc: dev@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. > 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. :-) 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). -+ Tatu +-