Skip to content
This repository

Extension module to properly support full datatype set of Joda datetime library

Merge pull request #36 from mveitas/interval

Adding tests for the Interval serializer and deserializer
latest commit f653781a1f
Tatu Saloranta cowtowncoder authored
Octocat-spinner-32 release-notes Implemented #32 March 04, 2014
Octocat-spinner-32 src Adding tests for the Interval serializer and deserializer April 02, 2014
Octocat-spinner-32 .gitignore ... March 06, 2012
Octocat-spinner-32 README.md ... January 20, 2014
Octocat-spinner-32 pom.xml Implemented #32 March 04, 2014
README.md

Project to build Jackson module (jar) to support JSON serialization and deserialization of Joda data types.

Status

Build Status

As of version 2.0 module is usable and relatively extensive. Contributions are always welcome -- not all types are yet supported; and we may want to support even wider alternative formats on input side.

Usage

Since this module extends basic Jackson databind functionality, you may want to check out documentation at Jackson-docs first.

Maven dependency

To use module on Maven-based projects, use following dependency:

<dependency>
  <groupId>com.fasterxml.jackson.datatype</groupId>
  <artifactId>jackson-datatype-joda</artifactId>
  <version>2.3.1</version>
</dependency>    

(or whatever version is most up-to-date at the moment)

Registering module

To use Joda datatypes with Jackson, you will first need to register the module first (same as with all Jackson datatype modules):

ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JodaModule());

Reading and Writing Joda types

After registering Joda module, Jackson Databind will be able to write values of supported Joda types as JSON (and other formats Jackson supports), and read Joda values from same formats.

With JSON, for example, following would work

public class Bean {
  public DateTime start;
}

final String INPUT_JSON = "{\"start\" : \"1972-12-28T12:00:01.000Z\"}";
Bean bean = mapper.readValue(INPUT_JSON, Bean.class);

and property start of Bean would have expected DateTime value.

Conversely, you can produce JSON (and other supported formats) simply with:

String json = mapper.writeValueAsString(bean);
Assert.assertEquals(INPUT_JSON, json);

More

See Wiki for more information (javadocs, downloads).

Something went wrong with that request. Please try again.