users@glassfish.java.net

Re: Jersey _at_ Glassfish - POJOMappingFeature

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Tue, 18 Jan 2011 10:06:03 +0100

On Jan 17, 2011, at 11:18 PM, Witold Szczerba wrote:

> Hi there,
> I am having trouble configuring Jersey in Java EE 6 application on
> Glassfish 3.0.1.
> Chapter 5.1 of Jersey User Guide
> http://jersey.java.net/nonav/documentation/latest/json.html#d0e1960
> says that in order to enable POJOMappingFeature one has to turn
> JSONConfiguration.FEATURE_POJO_MAPPING on using servlet init
> parameter. The problem is there is no servlet definition, the only
> thing to enable JAX-WS is to create a class like this:
>
> @javax.ws.rs.ApplicationPath("resources")
> public class EnableJAXRS extends javax.ws.rs.core.Application{
>
> }
>
> Can you help me?
>

There are two ways:

1) Create a web.xml and declare a servlet with a servlet name the same
as the fully qualified class name of EnableJAXRS.

For example:

<web-app version="3.0">
     <servlet>
         <servlet-name>... EnableJAXRS</servlet-name>
         <init-param>
             <param-name>com.sun.jersey.api.json.POJOMappingFeature</
param-name>
             <param-value>true</param-value>
         </init-param>
     </servlet>
</web-app>

2) Modify EnableJAXRS to extend from Jersey's DefaultResourceConfig
and in the constructor do:

   getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, true);

Paul.