diff --git a/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/jackson/PigJavaTimeModule.java b/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/jackson/PigJavaTimeModule.java index f51ac79c..f7f3341f 100644 --- a/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/jackson/PigJavaTimeModule.java +++ b/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/jackson/PigJavaTimeModule.java @@ -18,19 +18,10 @@ 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 com.fasterxml.jackson.datatype.jsr310.deser.*; +import com.fasterxml.jackson.datatype.jsr310.ser.*; -import java.time.Instant; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; +import java.time.*; import java.time.format.DateTimeFormatter; /** @@ -54,6 +45,8 @@ public class PigJavaTimeModule extends SimpleModule { this.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ISO_LOCAL_TIME)); // Instant 类型序列化 this.addSerializer(Instant.class, InstantSerializer.INSTANCE); + // Duration 类型序列化 + this.addSerializer(Duration.class, DurationSerializer.INSTANCE); // ======================= 时间反序列化规则 ============================== // yyyy-MM-dd HH:mm:ss @@ -64,6 +57,8 @@ public class PigJavaTimeModule extends SimpleModule { this.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ISO_LOCAL_TIME)); // Instant 反序列化 this.addDeserializer(Instant.class, InstantDeserializer.INSTANT); + // Duration 反序列化 + this.addDeserializer(Duration.class, DurationDeserializer.INSTANCE); } }