tech.simter:simter-jackson-ext

Simter Parent

License

License

MIT
Categories

Categories

Jackson Data JSON
GroupId

GroupId

tech.simter
ArtifactId

ArtifactId

simter-jackson-ext
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

Simter Parent
Project URL

Project URL

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

Project Organization

simter
Source Code Management

Source Code Management

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

Download simter-jackson-ext

How to add to project

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

Dependencies

compile (3)

Group / Artifact Type Version
com.fasterxml.jackson.core : jackson-databind jar
org.jetbrains.kotlin : kotlin-stdlib jar 1.3.11
org.slf4j : slf4j-api jar

test (15)

Group / Artifact Type Version
com.fasterxml.jackson.module : jackson-module-kotlin jar
org.springframework : spring-webflux jar
org.springframework.boot : spring-boot-autoconfigure jar
io.projectreactor : reactor-test jar
org.springframework.boot : spring-boot-starter-test jar
org.springframework.boot : spring-boot-starter-json jar
org.junit.jupiter : junit-jupiter-api jar 5.3.2
org.junit.jupiter : junit-jupiter-engine jar 5.3.2
org.junit.platform : junit-platform-runner jar 1.3.2
org.mockito : mockito-core jar 2.23.4
org.mockito : mockito-junit-jupiter jar 2.23.4
com.nhaarman : mockito-kotlin jar 1.6.0
org.slf4j : jcl-over-slf4j jar
ch.qos.logback : logback-classic jar
com.jayway.jsonpath : json-path-assert jar

Project Modules

There are no modules declared in this project.

simter-jackson-ext

This module was deprecated, please use simter-jackson-javatime instead.

A brand new Jackson Java 8 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 would be config to another format by customization in the future.

1. Installation

<dependency>
  <groupId>tech.simter</groupId>
  <artifactId>simter-jackson-ext</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
1.0.0