mirror of https://gitee.com/maxjhandsome/pig
🐛 Fixing a bug. closed #I47AHI Java 8 date/time type `java.time.Instant` not supported by default
This commit is contained in:
parent
2d2eb1f6fc
commit
2fcee0ff80
|
@ -18,13 +18,16 @@ package com.pig4cloud.pig.common.core.jackson;
|
|||
import cn.hutool.core.date.DatePattern;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.PackageVersion;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.InstantSerializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
|
@ -41,18 +44,33 @@ public class PigJavaTimeModule extends SimpleModule {
|
|||
|
||||
public PigJavaTimeModule() {
|
||||
super(PackageVersion.VERSION);
|
||||
|
||||
// ======================= 时间序列化规则 ===============================
|
||||
// yyyy-MM-dd HH:mm:ss
|
||||
this.addSerializer(LocalDateTime.class,
|
||||
new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN)));
|
||||
// yyyy-MM-dd
|
||||
this.addSerializer(LocalDate.class,
|
||||
new LocalDateSerializer(DateTimeFormatter.ofPattern(DatePattern.NORM_DATE_PATTERN)));
|
||||
// HH:mm:ss
|
||||
this.addSerializer(LocalTime.class,
|
||||
new LocalTimeSerializer(DateTimeFormatter.ofPattern(DatePattern.NORM_TIME_PATTERN)));
|
||||
|
||||
// Instant 类型序列化
|
||||
this.addSerializer(Instant.class, InstantSerializer.INSTANCE);
|
||||
|
||||
// ======================= 时间反序列化规则 ==============================
|
||||
// yyyy-MM-dd HH:mm:ss
|
||||
this.addDeserializer(LocalDateTime.class,
|
||||
new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN)));
|
||||
// yyyy-MM-dd
|
||||
this.addDeserializer(LocalDate.class,
|
||||
new LocalDateDeserializer(DateTimeFormatter.ofPattern(DatePattern.NORM_DATE_PATTERN)));
|
||||
// HH:mm:ss
|
||||
this.addDeserializer(LocalTime.class,
|
||||
new LocalTimeDeserializer(DateTimeFormatter.ofPattern(DatePattern.NORM_TIME_PATTERN)));
|
||||
// Instant 反序列化
|
||||
this.addDeserializer(Instant.class, InstantDeserializer.INSTANT);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue