fix(wms,oms): JSON日期反序列化兼容yyyy-MM-dd纯日期格式

- 库存查询日期只保留年月日后,前端回传纯日期(如 createTime=2026-07-06)触发
  @JsonFormat("yyyy-MM-dd HH:mm:ss") 严格格式反序列化 InvalidFormatException
- 新增 FlexibleDateDeserializer:字段 @JsonFormat 模式优先严格解析,失败后兼容
  yyyy-MM-dd HH:mm:ss / yyyy-MM-dd HH:mm / yyyy-MM-dd / 时间戳 / ISO-8601
- 仅在 OMS/WMS 通过 Module Bean 注册生效,不改动 BaseVOEntity 全局行为
This commit is contained in:
rcx
2026-09-05 13:38:06 +08:00
parent 762c49cd0f
commit c0bcedbdc3
3 changed files with 178 additions and 0 deletions
@@ -0,0 +1,33 @@
package com.mhd.oms.config;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.mhd.common.core.jackson.FlexibleDateDeserializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Date;
/**
* JSON 日期反序列化兼容配置:Date 字段兼容 yyyy-MM-dd(纯日期)等格式。
*
* 背景:库存查询日期只保留年月日后,前端回传纯日期(如 createTime=2026-07-06)时,
* 实体/DTO 上 @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 严格格式反序列化报
* InvalidFormatException。注册 FlexibleDateDeserializer 后优先按字段 @JsonFormat
* 严格解析,失败时兼容纯日期等常见格式(与 WMS 库存查询一致)。
*
* Spring Boot 会自动把容器中的 Module Bean 注册进 MVC 使用的 ObjectMapper。
*
* @author rcx
* @date 2026-09-05
*/
@Configuration
public class DateCompatibilityConfig {
@Bean
public Module flexibleDateModule() {
SimpleModule module = new SimpleModule("oms-flexible-date-module");
module.addDeserializer(Date.class, new FlexibleDateDeserializer());
return module;
}
}