Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

com.github.joschi.jackson:jackson-datatype-threetenbp

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

com.github.joschi.jackson:jackson-datatype-threetenbp

Add-on module to support ThreeTen backport (Java 8 Date & Time API for Java 6/7) data types.

  • 2.15.2
  • Source
  • Maven
  • Socket score

Version published
Maintainers
1
Source

jackson-datatype-threetenbp

Datatype module to make Jackson recognize the ThreeTen data types (backport of the Java 8 Date & Time API).

Status

Build Status Coverage Status Maven Central Javadocs

Generally available as of Jackson 2.4 and Java 1.6.

Summary

Most ThreeTenBP types are serialized as numbers (integers or decimals as appropriate) if the SerializationFeature#WRITE_DATES_AS_TIMESTAMPS feature is enabled, and otherwise are serialized in standard ISO-8601 string representation. ISO-8601 specifies formats for representing offset dates and times, zoned dates and times, local dates and times, periods, durations, zones, and more. All ThreeTenBP types have built-in translation to and from ISO-8601 formats.

Granularity of timestamps is controlled through the companion features SerializationFeature#WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS and DeserializationFeature#READ_DATE_TIMESTAMPS_AS_NANOSECONDS. For serialization, timestamps are written as fractional numbers (decimals), where the number is seconds and the decimal is fractional seconds, if WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS is enabled (it is by default), with resolution as fine as nanoseconds depending on the underlying JDK implementation. If WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS is disabled, timestamps are written as a whole number of milliseconds. At deserialization time, decimal numbers are always read as fractional second timestamps with up-to-nanosecond resolution, since the meaning of the decimal is unambiguous. The more ambiguous integer types are read as fractional seconds without a decimal point if READ_DATE_TIMESTAMPS_AS_NANOSECONDS is enabled (it is by default), and otherwise they are read as milliseconds.

Some exceptions to this standard serialization/deserialization rule:

  • Period, which always results in an ISO-8601 format because Periods must be represented in years, months, and/or days.
  • Year, which only contains a year and cannot be represented with a timestamp.
  • YearMonth, which only contains a year and a month and cannot be represented with a timestamp.
  • MonthDay, which only contains a month and a day and cannot be represented with a timestamp.
  • ZoneId and ZoneOffset, which do not actually store dates and times but are supported with this module nonetheless.
  • LocalDate, LocalTime, LocalDateTime, and OffsetTime, which cannot portably be converted to timestamps and are instead represented as arrays when WRITE_DATES_AS_TIMESTAMPS is enabled.

Usage

Maven dependency

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

<dependency>
    <groupId>com.github.joschi.jackson</groupId>
    <artifactId>jackson-datatype-threetenbp</artifactId>
    <version>${jackson.version}</version>
</dependency>

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

Registering module

As of Jackson 2.2, Modules can be automatically discovered using the Java 6 Service Provider Interface (SPI) feature. You can activate this by instructing an ObjectMapper to find and register all Modules:

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

You should use this feature with caution as it has performance implications. You should generally create one constant ObjectMapper instance for your entire application codebase to share, or otherwise use one of ObjectMapper's findModules methods and cache the result.

If you prefer to selectively register this module, this is done as follows, without the call to findAndRegisterModules():

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

After either of these, functionality is available for all normal Jackson operations.

FAQs

Package last updated on 14 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc