users@jersey.java.net

Re: [Jersey] JSONP

From: Jakub Podlesak <Jakub.Podlesak_at_Sun.COM>
Date: Fri, 22 Jan 2010 11:16:30 +0100

On Thu, Jan 21, 2010 at 01:09:14PM -0800, Tatu Saloranta wrote:
> On Thu, Jan 21, 2010 at 6:43 AM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:
> >
> ...
> >>> 3) Jersey declares to Jackson an exclude list of classes or package.
> >>
> >> That would mean changes in Jackson.
> >
> > Yes. Jackson does have a concept of an "exclude" list:
> >
> >    public final static HashSet<ClassKey> _untouchables = new
> > HashSet<ClassKey>();
> >    static {
> ...
> >        // Then core JAX-RS things
> >        _untouchables.add(new ClassKey(StreamingOutput.class));
> >        _untouchables.add(new ClassKey(Response.class));
> >    }
> >
> > Note the latter two. I think an extensible solution, where something else
> > can also add to the "untouchables" list, may be worth exploring further as i
> > think that would be the best solution to solve the problem.
>
> 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.

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?

~Jakub

>
> -+ Tatu +-
>
> ---------------------------------------------------------------------
> 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