Jersey 2.0 equivalent to POJOMappingFeature Jersey 2.0 equivalent to POJOMappingFeature json json

Jersey 2.0 equivalent to POJOMappingFeature


Please use the below dependency which will do it automatically for you.

 <dependency>        <groupId>com.fasterxml.jackson.jaxrs</groupId>        <artifactId>jackson-jaxrs-json-provider</artifactId>        <version>2.2.3</version>   </dependency>


If you want to define it in your web.xml file then:

JACKSON:

<init-param>  <param-name>jersey.config.server.provider.classnames</param-name>  <param-value>org.glassfish.jersey.jackson.JacksonFeature</param-value></init-param>

MOXY

<init-param>  <param-name>jersey.config.server.provider.classnames</param-name>  <param-value>org.glassfish.jersey.moxy.json.MoxyFeature</param-value></init-param>

And if using maven add the following dependency to your pom file

JACKSON

<dependency>    <groupId>org.glassfish.jersey.media</groupId>    <artifactId>jersey-media-json-jackson</artifactId>    <version>your jersey version</version></dependency>

MOXY

<dependency>    <groupId>org.glassfish.jersey.media</groupId>    <artifactId>jersey-media-moxy</artifactId>    <version>your jersey version</version></dependency>


You can configure EclipseLink MOXy as the JSON-binding provider by configuring the MOXyJsonProvider class through a JAX-RS Application class.

Example #1

package org.example;import java.util.*;import javax.ws.rs.core.Application;import org.eclipse.persistence.jaxb.rs.MOXyJsonProvider;public class CustomerApplication  extends Application {    @Override    public Set<Class<?>> getClasses() {        HashSet<Class<?>> set = new HashSet<Class<?>>(2);        set.add(MOXyJsonProvider.class);        set.add(CustomerService.class);        return set;    }}

Example #2

package org.example;import java.util.*;import javax.ws.rs.core.Application;import org.eclipse.persistence.jaxb.rs.MOXyJsonProvider;public class CustomerApplication  extends Application {    @Override    public Set<Class<?>> getClasses() {        HashSet<Class<?>> set = new HashSet<Class<?>>(1);        set.add(ExampleService.class);        return set;    }    @Override    public Set<Object> getSingletons() {        MOXyJsonProvider moxyJsonProvider = new MOXyJsonProvider();        moxyJsonProvider.setAttributePrefix("@");        moxyJsonProvider.setFormattedOutput(true);        moxyJsonProvider.setIncludeRoot(true);        moxyJsonProvider.setMarshalEmptyCollections(false);        moxyJsonProvider.setValueWrapper("$");        Map<String, String> namespacePrefixMapper = new HashMap<String, String>(1);        namespacePrefixMapper.put("http://www.example.org/customer", "cust");        moxyJsonProvider.setNamespacePrefixMapper(namespacePrefixMapper);        moxyJsonProvider.setNamespaceSeparator(':');        HashSet<Object> set = new HashSet<Object>(1);        set.add(moxyJsonProvider);        return set;    }} 

For More Information