Skip to content

Commit

Permalink
Merge pull request #121 from hocgin/develop
Browse files Browse the repository at this point in the history
[新增功能](develop): 用户配置
  • Loading branch information
hocgin authored Apr 21, 2023
2 parents 01cd521 + 2c08fe1 commit de7130d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package in.hocg.boot.web.autoconfiguration.jackson;

import in.hocg.boot.web.autoconfiguration.jackson.localdatetime.LocalDateTimeDeserializer;
import in.hocg.boot.web.autoconfiguration.jackson.xlong.LongDeserializer;
import in.hocg.boot.web.autoconfiguration.jackson.xlong.LongSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.LocalDateTime;

/**
* Created by hocgin on 2020/9/4
* email: [email protected]
Expand All @@ -19,7 +22,7 @@ public class SerializerConfiguration {
public Jackson2ObjectMapperBuilderCustomizer jacksonCustomizer() {
return builder -> {
// builder.serializerByType(LocalDateTime.class, new LocalDateTimeSerializer());
// builder.deserializerByType(LocalDateTime.class, new LocalDateTimeDeserializer());
builder.deserializerByType(LocalDateTime.class, new LocalDateTimeDeserializer());
builder.serializerByType(Long.class, new LongSerializer());
builder.deserializerByType(Long.class, new LongDeserializer());
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package in.hocg.boot.web.autoconfiguration.jackson.localdatetime;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
Expand All @@ -21,7 +23,11 @@ public class LocalDateTimeDeserializer extends JsonDeserializer<LocalDateTime> {
@Override
public LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
if (Objects.nonNull(p) && StrUtil.isNotBlank(p.getText())) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(p.getLongValue()), ZoneOffset.of("+8"));
String text = p.getText();
if (NumberUtil.isLong(text)) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(p.getLongValue()), ZoneOffset.of("+8"));
}
return Convert.toLocalDateTime(text);
}
return null;
}
Expand Down

0 comments on commit de7130d

Please sign in to comment.