mirror of
https://gitee.com/smallc/blade-tool.git
synced 2026-08-24 20:31:16 +08:00
🐛 修复Blade时间模块与官方模块标识冲突导致Instant等类型序列化失败
This commit is contained in:
parent
9bceec2067
commit
583fd83b88
|
|
@ -16,6 +16,7 @@
|
|||
package org.springblade.core.tool.jackson;
|
||||
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.PackageVersion;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
|
|
@ -32,12 +33,18 @@ import java.time.LocalTime;
|
|||
/**
|
||||
* java 8 时间默认序列化
|
||||
*
|
||||
* <p>
|
||||
* 仅覆盖 LocalDateTime、LocalDate、LocalTime 的格式,其余类型由官方 {@link JavaTimeModule} 处理。
|
||||
* 模块名须显式声明:SimpleModule 以 Version 的 artifactId 为模块标识,沿用 jsr310 的 PackageVersion
|
||||
* 会与官方模块同名,被去重逻辑判为重复注册而互相顶替。
|
||||
* </p>
|
||||
*
|
||||
* @author L.cm
|
||||
*/
|
||||
public class BladeJavaTimeModule extends SimpleModule {
|
||||
|
||||
public BladeJavaTimeModule() {
|
||||
super(PackageVersion.VERSION);
|
||||
super("BladeJavaTimeModule", PackageVersion.VERSION);
|
||||
this.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeUtil.DATETIME_FORMAT));
|
||||
this.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeUtil.DATE_FORMAT));
|
||||
this.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeUtil.TIME_FORMAT));
|
||||
|
|
|
|||
|
|
@ -979,12 +979,12 @@ public class JsonUtil {
|
|||
super.setTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault()));
|
||||
//序列化时,日期的统一格式
|
||||
super.setDateFormat(new SimpleDateFormat(DateUtil.PATTERN_DATETIME, Locale.CHINA));
|
||||
//日期格式化
|
||||
super.registerModule(new BladeJavaTimeModule());
|
||||
//视图注解内省器,让 Jackson 识别 @BladeView
|
||||
super.setAnnotationIntrospector(new BladeViewAnnotationIntrospector());
|
||||
//注册模块
|
||||
super.findAndRegisterModules();
|
||||
//日期格式化,须后于官方模块注册以覆盖其格式
|
||||
super.registerModule(new BladeJavaTimeModule());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user