Use Apache Wink with the Jackson JSON processor

Simpler JAX-RS integration with Ajax


Apache Wink is becoming one of the de facto implementations of the JAX-RS specification. and Jettison, the default providers for JSON synchronization, have some problems. For example, their array representation and limited return types make coding JAX-RS services, and their client Ajax applications, difficult.

This article outlines a method for configuring an existing Apache Wink-enabled Web application to use the Jackson JSON provider. Learn about the advantages of this provider by using sample code for a simple Jackson-enabled JAX-RS Web service.

JSON providers packaged with Apache Wink

Apache Wink packages two JSON providers as part of the standard distribution: and Jettison implementations. Both of these providers have issues that complicate the integration of Wink services with Ajax applications. Neither provider can directly serialize a Java List to JSON as a return type because of the JAXB requirement for an encompassing XML element. Both providers also have additional problems, such as:
Array serialization with the provider is predictable, but the behavior is undesirable when interacting with Ajax. When presented with arrays of varying sizes, represents them differently:
  • 2+ : "Correct" array serialization. For example: object : { array : ["element1", "element2"] }
  • 1 : Collapses the array. For example: object : { array : "element1" }
  • 0 : Removes the array entirely. For example: object : { }

It's clear that coding allowances for the different structures in Javascript make for extra, undesired complexity.

Jettison uses the Badgerfish convention for JSON generation, producing structures that can be hard to navigate after they're converted to Javascript objects.


At its core, Jackson is a JSON processor used for both generation and parsing of JSON representations of Java objects. Jackson can also be configured as a JSON serialization provider for JAX-RS implementations.

As a JAX-RS JSON serialization provider, Jackson has several advantages over its and Jettison counterparts, as described below.

Table 1. Jackson advantages
Ability to serialize Lists nativelyJackson can directly return a List of string objects from a service without a wrapper Xml element.
Array handling Jackson has excellent, predictable array serialization facilities.
Speed Measurably faster than other providers.
LicensingThe Apache License 2.0 is well-understood. Components using this license are used in both commercial and free software products.

Configuring Apache Wink for Jackson

The instructions for the example in this article assume that:

  • You have an existing dynamic Web project configured to use Apache Wink as a JAX-RS provider.
  • The Wink servlet, org.apache.wink.server.internal.servlet.RestServlet, is configured in the web.xml file to use a JAX-RS application, as shown in Listing 1.
Listing 1. web.xml snippet for Wink servlet

Download and install Jackson libraries

From the Jackson Web site, download the latest version of the Jackson provider (see Related topics for a link). At the time of writing, the Jackson team does not provide a single download resource for all the libraries required to use Jackson with Apache Wink. You'll need either ASL or LGPL versions of the JAR files, as follows.

  • core-(asl/lgpl): the Jackson core functions
  • mapper-(asl/lgpl): POJO <-> JSON serialization
  • jax-rs: the interface between Wink and Jackson
  • jax-xc: backwards compatibility with JAXB annotations

The JAR files must be present on the classpath of your Web project. The simplest way to do this is to place them in your WEB-INF/lib directory. (It is likely that your Apache Wink JAR files are already in this directory.)

Configure Apache Wink to use the Jackson provider for JSON serialization

At this point, the Jackson JSON provider is being loaded as part of your Web application, but Apache Wink has not been instructed to use it for JSON serialization.

Adjust the Wink servlet's configured application to load the provider, as shown in Listing 2.

Listing 2. Sample

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


// Jackson imports
import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector;

public class WinkApplication extends Application {

   * Get the list of service classes provided by this JAX-RS application
  public Set<Class<?>> getClasses() {
    Set<Class<?>> serviceClasses = new HashSet<Class<?>>();
    return serviceClasses;
  public Set<Object> getSingletons() {
    Set<Object> s = new HashSet<Object>();
    // Register the Jackson provider for JSON
    // Make (de)serializer use a subset of JAXB and (afterwards) Jackson annotations
    // See for more information
    ObjectMapper mapper = new ObjectMapper();
    AnnotationIntrospector primary = new JaxbAnnotationIntrospector();
    AnnotationIntrospector secondary = new JacksonAnnotationIntrospector();
    AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary);
    // Set up the provider
    JacksonJaxbJsonProvider jaxbProvider = new JacksonJaxbJsonProvider();
    return s;


Direct List<?> serialization

Jackson gives you the opportunity to easily return Java Lists from their functions, without the need for a wrapper JAXB XML element. Listing 3 shows an example.

Listing 3.

import java.util.Arrays;
import java.util.List;


public class HelloWorlds {
  public List<String> helloWorlds() {
    return Arrays.asList(new String [] {"Hello Earth!",  "Hello Mars!" });


Apache Wink is increasingly used as an implementation of the JAX-RS specification. and Jettison, the default providers for JSON synchronization, have some problems. In this article, you learned about a method for configuring an existing Apache Wink-enabled Web application to use the Jackson JSON provider. An example highlighted the advantages of this provider by using sample code for a simple Jackson-enabled JAX-RS Web service.

Downloadable resources

Related topics


Sign in or register to add and subscribe to comments.

Zone=Web development, Java development, SOA and web services
ArticleTitle=Use Apache Wink with the Jackson JSON processor