Skip to content

About

Set of support modules for Java 8 datatypes (Optionals, date/time) and features (parameter names)

Topics

Resources

Stars

425 stars

Watchers

14 watching

Forks

 
 

Repository files navigation

Overview

This is a multi-module umbrella project for Jackson modules needed to support Java 8 features when core Jackson modules do not (yet) require Java 8 runtime (note: Jackson 3.0 will likely increase baseline and allow including some or all of this functionality)

For Jackson 2.x this includes 3 modules:

  • Parameter names: support for detecting constructor and factory method ("creator") parameters without having to use @JsonProperty annotation
    • provides com.fasterxml.jackson.module.paramnames.ParameterNamesModule
  • Java 8 Date/time: support for Java 8 date/time types (specified in JSR-310 specification)
    • provides com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
    • ALSO provides legacy variant com.fasterxml.jackson.datatype.jsr310.JSR310TimeModule
    • difference between 2 modules is that of configuration defaults: use of JavaTimeModule strongly recommended for new code
  • Java 8 Datatypes: support for other new Java 8 datatypes outside of date/time: most notably Optional, OptionalLong, OptionalDouble
    • provides com.fasterxml.jackson.datatype.jdk8.Jdk8Module

all of which are built from this repository, and accessed and used as separate Jackson modules (with separate Maven artifacts).

Jackson 3.x changes things so that parameter-names and datatypes modules are merged into jackson-databind and need not be registered; datetime module (JavaTimeModule) remains separate module due to its size and configurability options.

License

All modules are licensed under Apache License 2.0.

Status

Build Status

Usage

Maven dependencies

To include modules, you use some or all of:

<dependency>
    <groupId>com.fasterxml.jackson.module</groupId>
    <artifactId>jackson-module-parameter-names</artifactId>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-jdk8</artifactId>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-jsr310</artifactId>
</dependency>

and either include versions directly, OR, preferably, import Jackson BOM that will specify consistent version set.

Registering modules

ObjectMapper mapper = new ObjectMapper()
   .registerModule(new ParameterNamesModule())
   .registerModule(new Jdk8Module())
   .registerModule(new JavaTimeModule()) // new module, NOT JSR310Module
;

or, alternatively, you can also auto-discover these modules with:

ObjectMapper mapper = new ObjectMapper();
mapper.findAndRegisterModules();

Either way, after registration all functionality is available for all normal Jackson operations.

WARNING - As of Jackson 2.x, auto-registration will only register older JSR310Module, and not newer JavaTimeModule -- this is due to backwards compatibility. Because of this make sure to either use explicit registration, or, if you want to use JavaTimeModule but also auto-registration, make sure to register JavaTimeModule BEFORE calling mapper.findAndRegisterModules()).

More

See Wiki for more information (javadocs).

About

Set of support modules for Java 8 datatypes (Optionals, date/time) and features (parameter names)

Topics

Resources

Stars

425 stars

Watchers

14 watching

Forks

Releases

Packages

Used by

Contributors

Languages