users@jersey.java.net

Re: [Jersey] JSONP

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Fri, 22 Jan 2010 12:43:06 -0800

On Fri, Jan 22, 2010 at 2:16 AM, Jakub Podlesak <Jakub.Podlesak_at_sun.com> wrote:
...
>> Additionally, if there was a good way to pass per-request information,
>> jackson provider could quite easily add necessary prefix (json
>> function name, open-paren) before output, and suffix (close-paren)
>> afterwards. But it would have to know when to do this (and with what
>> function name).
>
> From Jersey standpoint, the issue is not that Jackson does not have the capability
> to serialize from Java to JavaScript, but that in this case it serializes (from Java to JSON)
> also data not intended for serialization.

Ok. What does the wrapper object look like? There might be a way to
handle it specifically.

> What could help would be a way to tell Jackson to filter incoming Java objects
> before processing. If Jackson e.g. provides a way to register a simple filter
>
> public interface Filter {
>  public Object filter(Object o);
> }
>
> Jersey could implement and register such a filter for the JSONWithPadding wrapper,
> which would leave all other objects intact.
>
> I think the filter thing would be quite generic, so that it could be used also for another
> purpose if something appears in the future.
>
> Would it work for you?

There is no direct support for that, although recent (1.4) work for
JsonView did open up some possibilities for filtering. It could be
used, but would still require bit of custom (used by jersey) code,
either custom serializer/deserializer for wrapper type, or bean
factory overrides.

But in general this sounds like the way to go, if wrapper type is
always the same (or can be auto-detected easily). Might require some
changes to jackson jax-rs provider, perhaps to support jersey-specific
sub-class (or add on if need be).

-+ Tatu +-