users@jersey.java.net

[Jersey] Re: Howto enable JSON support for Jersey2 in Glassfish?

From: Arul Dhesiaseelan <aruld_at_acm.org>
Date: Sat, 26 Jan 2013 11:19:01 -1000

Hi Jan,

You can enable Jackson/Jettison feature on the server-side by registering
features in the JAX-RS application. No web.xml required. Here is an
example.

@ApplicationPath("/")
public class MyApplication extends Application {

    @Override
    public Set<Class<?>> getClasses() {
        final Set<Class<?>> classes = new HashSet<Class<?>>();
        classes.add(ClusterResource.class);
        return classes;
    }

    @Override
    public Set<Object> getSingletons() {
        final Set<Object> instances = new HashSet<Object>();
        instances.add(new JacksonFeature());
        instances.add(new LoggingFilter());
        return instances;
    }
}

GF4 bundles Jersey 2 m11, so you should be good to go. I put together a
simple project that shows this end-to-end running on GlassFish 4 b72 [1].


-Arul

[1] https://github.com/aruld/jersey2-sample


On Fri, Jan 25, 2013 at 11:40 PM, Jan Algermissen <
jan.algermissen_at_nordsc.com> wrote:

> Hi,
>
> I am feeling kinda like an idiot to ask this, but...
>
> how do I enable JSON (JAXB serialisation) for Jersey 2 in Glassfish?
>
> Building with maven; preferably not having a web.xml.
>
> Jan
>