tech.simter:simter-jackson-javatime

Simter Dependencies

License

License

MIT
Categories

Categories

Jackson Data JSON
GroupId

GroupId

tech.simter
ArtifactId

ArtifactId

simter-jackson-javatime
Last Version

Last Version

0.3.0
Release Date

Release Date

Type

Type

jar
Description

Description

Simter Dependencies
Project URL

Project URL

https://github.com/simter/simter-jackson-javatime
Project Organization

Project Organization

simter
Source Code Management

Source Code Management

https://github.com/simter/simter-jackson-javatime.git

Download simter-jackson-javatime

How to add to project

<!-- https://jarcasting.com/artifacts/tech.simter/simter-jackson-javatime/ -->
<dependency>
    <groupId>tech.simter</groupId>
    <artifactId>simter-jackson-javatime</artifactId>
    <version>0.3.0</version>
</dependency>
// https://jarcasting.com/artifacts/tech.simter/simter-jackson-javatime/
implementation 'tech.simter:simter-jackson-javatime:0.3.0'
// https://jarcasting.com/artifacts/tech.simter/simter-jackson-javatime/
implementation ("tech.simter:simter-jackson-javatime:0.3.0")
'tech.simter:simter-jackson-javatime:jar:0.3.0'
<dependency org="tech.simter" name="simter-jackson-javatime" rev="0.3.0">
  <artifact name="simter-jackson-javatime" type="jar" />
</dependency>
@Grapes(
@Grab(group='tech.simter', module='simter-jackson-javatime', version='0.3.0')
)
libraryDependencies += "tech.simter" % "simter-jackson-javatime" % "0.3.0"
[tech.simter/simter-jackson-javatime "0.3.0"]

Dependencies

compile (1)

Group / Artifact Type Version
com.fasterxml.jackson.core : jackson-databind jar

test (8)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter jar
org.assertj : assertj-core jar 3.12.2
net.javacrumbs.json-unit : json-unit-assertj jar 2.7.0
org.slf4j : jcl-over-slf4j jar
ch.qos.logback : logback-classic jar
org.springframework.boot : spring-boot jar
org.jetbrains.kotlin : kotlin-stdlib jar
com.fasterxml.jackson.module : jackson-module-kotlin jar

Project Modules

There are no modules declared in this project.

simter-jackson-javatime

A brand new Jackson Java8+ Date & Time serialization and deserialization module with global localize config.

Jackson standard JavaTimeModule has a standard ISO-8601 format default, and it can not be config to another default format globally. That's too bad for real projects. This module do these things good. But it's not a extension of Jackson standard JavaTimeModule. It's a brand new module for setting global data-time format.

It is config to localize date-time format like yyyy-MM-dd HH:mm now, accurate to minute and without zone and offset info (global use local zone and offset default). That's more useful in my real projects. it can be config to another default format by customization in by JavaTimeFormat.JAVA_TIME_FORMATS.

For spring-boot project, use property simter.jackson.java-time.global-formats to config a custom default format, such as:

simter.jackson.java-time.global-formats:
  "[java.time.LocalDateTime]":
    pattern: "yyyy-MM-dd HH:mm:ss"
    shape: STRING

This is auto config by register JavaTimeConfiguration to spring.

1. Installation

<dependency>
  <groupId>tech.simter</groupId>
  <artifactId>simter-jackson-javatime</artifactId>
  <version>${VERSION}</version>
</dependency>

Exclude jackson-datatype-jsr310 for spring-boot:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-json</artifactId>
  <exclusions>
    <exclusion>
      <groupId>com.fasterxml.jackson.datatype</groupId>
      <artifactId>jackson-datatype-jsr310</artifactId>
    </exclusion>
  </exclusions>
</dependency>

2. Global default format

DateTime Class Value-Format Serialize To
OffsetDateTime yyyy-MM-dd HH:mm String
OffsetTime yyyy-MM-dd HH:mm String
ZonedDateTime yyyy-MM-dd HH:mm String
LocalDateTime yyyy-MM-dd HH:mm String
LocalDate yyyy-MM-dd String
LocalTime HH:mm String
Instant {EpochSecond} Number
YearMonth yyyyMM Number
Year yyyy Number
Month MM Number
MonthDay MM-dd String

3. Usage

3.1. Base usage

val mapper = ObjectMapper()
mapper.registerModule(tech.simter.jackson.ext.javatime.JavaTimeModule())

// Recommand to disabled and enabled some features:
mapper.setSerializationInclusion(NON_EMPTY)
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
mapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true)

3.2. WebFlux usage

See simter-reactive-web/.../WebFluxConfiguration.kt.

tech.simter

Versions

Version
0.3.0