From 0f2b99fd859f5235e7b42bad998fabd38a672dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= <2270033969@qq.com> Date: Thu, 31 Oct 2024 11:00:51 +0800 Subject: [PATCH] =?UTF-8?q?refactor(core):=20=E6=94=AF=E6=8C=81=20Duration?= =?UTF-8?q?=20=E7=B1=BB=E5=9E=8B=E5=BA=8F=E5=88=97=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/jackson/PigJavaTimeModule.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) 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); } }