From d6b426970b6e0fd86712ecbdecd201cd9f7d89aa Mon Sep 17 00:00:00 2001 From: halfninety <690534687@qq.com> Date: Tue, 29 Nov 2022 23:21:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=8F=E5=88=97=E5=8C=96=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/YudaoJacksonAutoConfiguration.java | 9 ++++++-- .../databind/LocalTimeDeserializable.java | 16 -------------- .../jackson/core/databind/LocalTimeJson.java | 21 +++++++++++++++++++ .../core/databind/LocalTimeSerializable.java | 17 --------------- 4 files changed, 28 insertions(+), 35 deletions(-) delete mode 100644 yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalTimeDeserializable.java create mode 100644 yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalTimeJson.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalTimeSerializable.java diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/config/YudaoJacksonAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/config/YudaoJacksonAutoConfiguration.java index c44e770a1..f3cad8d79 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/config/YudaoJacksonAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/config/YudaoJacksonAutoConfiguration.java @@ -1,8 +1,9 @@ package cn.iocoder.yudao.framework.jackson.config; +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.framework.jackson.core.databind.LocalDateTimeDeserializer; import cn.iocoder.yudao.framework.jackson.core.databind.LocalDateTimeSerializer; -import cn.iocoder.yudao.framework.common.util.json.JsonUtils; +import cn.iocoder.yudao.framework.jackson.core.databind.LocalTimeJson; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; import lombok.extern.slf4j.Slf4j; @@ -12,6 +13,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import java.time.LocalDateTime; +import java.time.LocalTime; @Configuration(proxyBeanMethods = false) @Slf4j @@ -30,12 +32,15 @@ public class YudaoJacksonAutoConfiguration { /* * 1. 新增Long类型序列化规则,数值超过2^53-1,在JS会出现精度丢失问题,因此Long自动序列化为字符串类型 * 2. 新增LocalDateTime序列化、反序列化规则 + * 3. 新增LocalTime序列化、反序列化规则 */ simpleModule // .addSerializer(Long.class, ToStringSerializer.instance) // .addSerializer(Long.TYPE, ToStringSerializer.instance) .addSerializer(LocalDateTime.class, LocalDateTimeSerializer.INSTANCE) - .addDeserializer(LocalDateTime.class, LocalDateTimeDeserializer.INSTANCE); + .addDeserializer(LocalDateTime.class, LocalDateTimeDeserializer.INSTANCE) + .addSerializer(LocalTime.class, LocalTimeJson.SERIALIZER) + .addDeserializer(LocalTime.class, LocalTimeJson.DESERIALIZABLE); objectMapper.registerModules(simpleModule); diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalTimeDeserializable.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalTimeDeserializable.java deleted file mode 100644 index 9735438b1..000000000 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalTimeDeserializable.java +++ /dev/null @@ -1,16 +0,0 @@ -package cn.iocoder.yudao.framework.jackson.core.databind; - -import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer; - -import java.time.ZoneId; -import java.time.format.DateTimeFormatter; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_HOUR_MINUTE_SECOND; - -public class LocalTimeDeserializable { - // TODO: 2022/11/15 修改名字 - public static final LocalTimeDeserializer INSTANCE = new LocalTimeDeserializer(DateTimeFormatter - .ofPattern(FORMAT_HOUR_MINUTE_SECOND) - .withZone(ZoneId.systemDefault())); - -} diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalTimeJson.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalTimeJson.java new file mode 100644 index 000000000..f9ff37511 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalTimeJson.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.framework.jackson.core.databind; + +import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer; + +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_HOUR_MINUTE_SECOND; + +public class LocalTimeJson { + + public static final LocalTimeSerializer SERIALIZER = new LocalTimeSerializer(DateTimeFormatter + .ofPattern(FORMAT_HOUR_MINUTE_SECOND) + .withZone(ZoneId.systemDefault())); + + public static final LocalTimeDeserializer DESERIALIZABLE = new LocalTimeDeserializer(DateTimeFormatter + .ofPattern(FORMAT_HOUR_MINUTE_SECOND) + .withZone(ZoneId.systemDefault())); + +} diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalTimeSerializable.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalTimeSerializable.java deleted file mode 100644 index d6eaed819..000000000 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalTimeSerializable.java +++ /dev/null @@ -1,17 +0,0 @@ -package cn.iocoder.yudao.framework.jackson.core.databind; - -import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer; - -import java.time.ZoneId; -import java.time.format.DateTimeFormatter; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_HOUR_MINUTE_SECOND; - -public class LocalTimeSerializable { - // TODO: 2022/11/15 修改名称 - - public static final LocalTimeSerializer INSTANCE = new LocalTimeSerializer(DateTimeFormatter - .ofPattern(FORMAT_HOUR_MINUTE_SECOND) - .withZone(ZoneId.systemDefault())); - -}