Feature: Jackson Modules

(see Jira entry JACKSON-297 for details)

One of major new functionality in Jackson 1.7 is the ability to register bundles of extended functionality as modules.

What is a Module?

Module is basically an implementation of org.codehaus.jackson.map.Module, defined as:

   1 public abstract class Module
   2 {
   3     public abstract String getModuleName();
   4     public abstract Version version();
   5     public abstract void setupModule(SetupContext context);
   6 }

Modules can be registered calling:

    objectMapper.registerModule(new MyModule());

which will result in Module.setupModule() getting called with context object that allows module to:

Use cases

Expected main use case for modules is to offer convenient way to add plug-in functionality to support data types of third-party libraries, without requiring support be directly added to core Jackson library. Some of initial candidates include:

Beyond specific third-party libraries, support could also be added for basic datatypes of non-Java JVM languages, such as:

This would specifically help with collection types that do not implement basic java.util interfaces (Collection, List, Set, Map).

Simple modules

For simple use cases there is a standard Module implementation, org.codehaus.jackson.map.module.SimpleModule, which can be used as follows:

    ObjectMapper mapper = new ObjectMapper();
    // basic module metadata just includes name and version (both for troubleshooting; but name needs to be unique)
    SimpleModule module = new SimpleModule("EnhancedDatesModule", new Version(0, 1, 0, "alpha"));
    // functionality includes ability to register serializers, deserializers, add mix-in annotations etc:
    module.addSerializer(MyBean.class, new MyCustomSerializer());
    module.addDeserializer(MyBean.class, new MyCustomSerializer());
    // and the magic happens here when we register module with mapper:

More advanced use cases often require implementing Module interface directly; SimpleModule implementation can be useful as the base.

Jackson Module projects

More details on currently active Jackson Module projects (including links to downloadable Module artifacts) can be found on Jackson Module Projects page.


JacksonFeatureModules (last edited 2011-10-30 17:02:41 by TatuSaloranta)

Copyright ©2009 FasterXML, LLC