JBoss.orgCommunity Documentation

Chapter 87. OverwriteDefaultProviders

87.1. Motivation
87.2. Usage
87.3. Example

There is set of providers embedded in eXo JAX-RS implementation.

Implementations of MessageBodyReader and MessageBodyWriters are taking care about serialization/deserialization of message body (HTTP request/response's body).

The next set of media and Java types processed automatically, thanks to embedded Readers (Writers).


In some case it may be required to use alternative provider for the same media and java type but such changes must not impact to any other services.

To be able overwrite default JAX-RS provider(s) developer need:

In example below see how to use Jackson JSON provider instead of embedded in eXo RESTful framework.

Create subclass of javax.ws.rs.core.Application with code as bellow and add it to the eXo Container configuration.

package org.exoplatform.test.jackson;

import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;

import java.util.HashSet;
import java.util.Set;

import javax.ws.rs.core.Application;

public class Application1 extends Application
{
   @Override
   public Set<Class<?>> getClasses()
   {
      Set<Class<?>> cls = new HashSet<Class<?>>(1);
      cls.add(Resource1.class);
      return cls;
   }

   @Override
   public Set<Object> getSingletons()
   {
      Set<Object> objs = new HashSet<Object>(1);
      objs.add(new JacksonJaxbJsonProvider());
      return objs;
   }
}

In this example we assumes Resource1 is Java class which carries JAX-RS annotations and it uses JSON. In this case RESTful framework will use JacksonJaxbJsonProvider for serializing/deserializing of all messages to/from Resource1. But it will not impact to other services in any kind.