mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-23 07:41:53 +08:00
序列化配置修改名称
This commit is contained in:
parent
61c4053cbb
commit
d6b426970b
@ -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);
|
||||
|
||||
|
@ -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()));
|
||||
|
||||
}
|
@ -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()));
|
||||
|
||||
}
|
@ -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()));
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user