WAS v8.5 > End-to-end paths > Web services - RESTful services > Use JSON content in JAX-RS application requests and responses > Step 4. Implement a resource method using JSON content for a request and response entity.

Implement a JSON resource method using JAXB annotated objects with IBM JSON4J

In WebSphere Application Server v8, the default JSON processor to handle serializing JAXB annotated classes to JSON is Jackson. To use the IBM JSON4J processor from previous Feature Packs for Web 2.0 instead, add a provider class. Jackson offers more advanced JSON processing. To use the IBM JSON4J processor in the application, add a Java class that extends the JSON4JJAXBProvider class to the application.

  1. If we use annotation scanning and do not specify all of the JAX-RS classes through a javax.ws.rs.core.Application subclass, then add a Java class that extends the com.ibm.websphere.jaxrs.providers.json4j.JSON4JJAXBProvider class. The following example illustrates a custom JSON4JJAXBProvider class:
    package com.example.jaxrs;
    @Provider
    @Consumes(value = {MediaType.APPLICATION_JSON, "application/javascript"})
    @Produces(value = {MediaType.APPLICATION_JSON, "application/javascript"})
    public class CustomJSON4JJAXBProvider extends
        com.ibm.websphere.jaxrs.providers.json4j.JSON4JJAXBProvider {}

  2. If we use a customized javax.ws.rs.core.Application class that lists your JAX-RS classes, add your customized JSON4JJAXBProvider to your Application subclass. The following example illustrates a customized Application subclass:
    package com.example.jaxrs;
    public class CustomApplication extends javax.ws.rs.core.Application {
    
        @Override
        public Set<Class<?>> getClasses() {
            Set<Class<?>> classes = new HashSet<Class<?>>();
            /* add your normal JAX-RS classes */
    
            classes.add(CustomJSON4JJAXBProvider.class);
            return classes;
        }}


Results

You are now using the IBM JSON4J processor for JAXB-to-JSON serialization instead of the default Jackson processor built in the product.


Related


Use JSON content in JAX-RS application requests and responses


Reference:

http://jackson.codehaus.org/


+

Search Tips   |   Advanced Search