File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed
spring-boot-web/web-spring-boot-autoconfigure/src/main/java/in/hocg/boot/web/autoconfiguration/jackson Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change 11package in .hocg .boot .web .autoconfiguration .jackson ;
22
3+ import in .hocg .boot .web .autoconfiguration .jackson .localdatetime .LocalDateTimeDeserializer ;
34import in .hocg .boot .web .autoconfiguration .jackson .xlong .LongDeserializer ;
45import in .hocg .boot .web .autoconfiguration .jackson .xlong .LongSerializer ;
56import org .springframework .boot .autoconfigure .jackson .Jackson2ObjectMapperBuilderCustomizer ;
67import org .springframework .context .annotation .Bean ;
78import org .springframework .context .annotation .Configuration ;
89
10+ import java .time .LocalDateTime ;
11+
912/**
1013 * Created by hocgin on 2020/9/4
1114 * email: hocgin@gmail.com
@@ -19,7 +22,7 @@ public class SerializerConfiguration {
1922 public Jackson2ObjectMapperBuilderCustomizer jacksonCustomizer () {
2023 return builder -> {
2124// builder.serializerByType(LocalDateTime.class, new LocalDateTimeSerializer());
22- // builder.deserializerByType(LocalDateTime.class, new LocalDateTimeDeserializer());
25+ builder .deserializerByType (LocalDateTime .class , new LocalDateTimeDeserializer ());
2326 builder .serializerByType (Long .class , new LongSerializer ());
2427 builder .deserializerByType (Long .class , new LongDeserializer ());
2528 };
Original file line number Diff line number Diff line change 11package in .hocg .boot .web .autoconfiguration .jackson .localdatetime ;
22
3+ import cn .hutool .core .convert .Convert ;
4+ import cn .hutool .core .util .NumberUtil ;
35import cn .hutool .core .util .StrUtil ;
46import com .fasterxml .jackson .core .JsonParser ;
57import com .fasterxml .jackson .databind .DeserializationContext ;
@@ -21,7 +23,11 @@ public class LocalDateTimeDeserializer extends JsonDeserializer<LocalDateTime> {
2123 @ Override
2224 public LocalDateTime deserialize (JsonParser p , DeserializationContext ctxt ) throws IOException {
2325 if (Objects .nonNull (p ) && StrUtil .isNotBlank (p .getText ())) {
24- return LocalDateTime .ofInstant (Instant .ofEpochMilli (p .getLongValue ()), ZoneOffset .of ("+8" ));
26+ String text = p .getText ();
27+ if (NumberUtil .isLong (text )) {
28+ return LocalDateTime .ofInstant (Instant .ofEpochMilli (p .getLongValue ()), ZoneOffset .of ("+8" ));
29+ }
30+ return Convert .toLocalDateTime (text );
2531 }
2632 return null ;
2733 }
You can’t perform that action at this time.
0 commit comments