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())); - -}