users@jersey.java.net

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

From: algermissen1971 <algermissen1971_at_mac.com>
Date: Wed, 30 Jan 2013 00:12:30 +0100

Hi Arul,

On 27.01.2013, at 02:26, Arul Dhesiaseelan <aruld_at_acm.org> wrote:

> You are welcome. It is a portable deployment approach.
>
> You could also extend ResourceConfig.
>
> @ApplicationPath("/")
> public class MyApplication extends ResourceConfig {
>
> public MyApplication() {
> registerClasses(ClusterResource.class);
> register(new JacksonFeature());
> }
> }

Both approaches seem to only register the classes I provide, at the same time dropping the result from the runtime's scan for providers.

Is that desired behavior? Do I need a web.xml if I want to *add* my classes?


I am doing this[1] with 2.0-m09 , not -m11. Can that be the reason?


[1] in m09 it is addSingletons(new JacksonFeature())









>
>
>
> On Sat, Jan 26, 2013 at 12:12 PM, Jan Algermissen <jan.algermissen_at_nordsc.com> wrote:
> Arul,
>
> thanks a lot.
>
> Doh - I totally forgot that I have to *extend* Application. I was looking for a method to call ... that hurts ;-)
>
> Jan
>
> On 26.01.2013, at 22:19, Arul Dhesiaseelan <aruld_at_acm.org> wrote:
>
> > 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
> >
>
>