|
|
@@ -17,6 +17,7 @@ import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.TimeZone;
|
|
|
|
|
|
import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
|
|
|
|
|
|
@@ -39,16 +40,17 @@ public class JacksonObjectMapper extends ObjectMapper {
|
|
|
|
|
|
// 设置Date类型格式化
|
|
|
this.setDateFormat(new SimpleDateFormat(DEFAULT_DATE_TIME_FORMAT));
|
|
|
+ this.setTimeZone(TimeZone.getDefault());
|
|
|
|
|
|
SimpleModule simpleModule = new SimpleModule()
|
|
|
+ // 将大数字类型自动转换为String类型,防止前端精度丢失(也可以直接使用@JsonFormat(shape = JsonFormat.Shape.STRING)注解)
|
|
|
+ .addSerializer(BigInteger.class, ToStringSerializer.instance)
|
|
|
+ .addSerializer(Long.class, ToStringSerializer.instance)
|
|
|
// 反序列化(设置LocalDateTime等日期时间类型格式化)
|
|
|
.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT)))
|
|
|
.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT)))
|
|
|
.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_FORMAT)))
|
|
|
- // 将大数字类型自动转换为String类型,防止前端精度丢失(也可以直接使用@JsonFormat(shape = JsonFormat.Shape.STRING)注解)
|
|
|
- .addSerializer(BigInteger.class, ToStringSerializer.instance)
|
|
|
- .addSerializer(Long.class, ToStringSerializer.instance)
|
|
|
- // 序列化
|
|
|
+// // 序列化
|
|
|
.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT)))
|
|
|
.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT)))
|
|
|
.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_FORMAT)));
|