|
|
@@ -9,9 +9,11 @@ import com.fasterxml.jackson.core.JsonParser.Feature;
|
|
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
|
import com.fasterxml.jackson.databind.JsonSerializer;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.fasterxml.jackson.databind.SerializationFeature;
|
|
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
|
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
|
|
import com.fasterxml.jackson.databind.ser.std.NullSerializer;
|
|
|
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|
|
import net.sf.json.JSONNull;
|
|
|
import org.springframework.context.annotation.Primary;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
@@ -60,6 +62,10 @@ public class JsonMapper extends ObjectMapper {
|
|
|
} ) );
|
|
|
// 时间格式化
|
|
|
this.configure ( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false );
|
|
|
+ // 支持 java.time 类型(LocalDate/LocalDateTime):未注册该模块时序列化会直接抛异常
|
|
|
+ this.registerModule ( new JavaTimeModule ( ) );
|
|
|
+ // 关闭时间戳输出,让 LocalDate 按 @JsonFormat/ISO 字符串返回,而不是 [2026,11,3] 数组
|
|
|
+ this.disable ( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS );
|
|
|
this.setDateFormat ( new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss" ) );
|
|
|
|
|
|
// 设置时区
|