From efb81270f26620ecc43b9b1a5a541539b2b2d9bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9A=96=E6=9A=96?= Date: Mon, 22 Oct 2018 14:16:29 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E4=BC=98=E5=8C=96=E6=80=A7=E8=83=BD:?= =?UTF-8?q?=E4=BC=98=E5=8C=96jdk1.8=E4=B8=8Bjackson=E7=9A=84=E5=BA=8F?= =?UTF-8?q?=E5=88=97=E5=8C=96=E8=A1=A8=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pigx-common/pigx-common-core/pom.xml | 13 +++++++++---- .../pigx/common/core/config/JacksonConfig.java | 11 +++++++---- .../src/main/resources/config/application-dev.yml | 4 ++++ .../src/main/resources/config/pigx-codegen-dev.yml | 3 --- pom.xml | 8 ++++++++ 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/pigx-common/pigx-common-core/pom.xml b/pigx-common/pigx-common-core/pom.xml index d95b0daec..6006be1af 100644 --- a/pigx-common/pigx-common-core/pom.xml +++ b/pigx-common/pigx-common-core/pom.xml @@ -70,12 +70,17 @@ org.springframework.boot spring-boot-starter-validation - com.fasterxml.jackson.module - jackson-modules-java8 - ${jackson.modules} - pom + jackson-module-parameter-names + + + com.fasterxml.jackson.datatype + jackson-datatype-jdk8 + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/config/JacksonConfig.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/config/JacksonConfig.java index f828857dd..eb2401d08 100644 --- a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/config/JacksonConfig.java +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/config/JacksonConfig.java @@ -22,6 +22,9 @@ package com.pig4cloud.pigx.common.core.config; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import com.fasterxml.jackson.module.paramnames.ParameterNamesModule; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; @@ -41,16 +44,16 @@ import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; public class JacksonConfig { /** * 针对JDK 1.8 特殊处理 - * .registerModule(new ParameterNamesModule()) - * .registerModule(new Jdk8Module()) - * .registerModule(new JavaTimeModule()); // new module, NOT JSR310Module * * @return */ @Bean public ObjectMapper getObjectMapper(Jackson2ObjectMapperBuilder builder) { ObjectMapper objectMapper = builder.createXmlMapper(false).build(); - objectMapper.findAndRegisterModules(); + ObjectMapper mapper = new ObjectMapper() + .registerModule(new ParameterNamesModule()) + .registerModule(new Jdk8Module()) + .registerModule(new JavaTimeModule()); // new module, NOT JSR310Module // 忽略json字符串中不识别的属性 objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); // 忽略无法转换的对象 diff --git a/pigx-config/src/main/resources/config/application-dev.yml b/pigx-config/src/main/resources/config/application-dev.yml index 9f1e379b9..6ffd458a0 100644 --- a/pigx-config/src/main/resources/config/application-dev.yml +++ b/pigx-config/src/main/resources/config/application-dev.yml @@ -7,6 +7,10 @@ spring: redis: password: host: redis + # Jackson配置 + jackson: + time-zone: GMT+8 + date-format: yyyy-MM-dd HH:mm:ss # 暴露监控端点 management: endpoints: diff --git a/pigx-config/src/main/resources/config/pigx-codegen-dev.yml b/pigx-config/src/main/resources/config/pigx-codegen-dev.yml index 133c73ab7..923770e6a 100644 --- a/pigx-config/src/main/resources/config/pigx-codegen-dev.yml +++ b/pigx-config/src/main/resources/config/pigx-codegen-dev.yml @@ -14,8 +14,5 @@ spring: username: root password: 123456 url: jdbc:mysql://mysql:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false - jackson: - time-zone: GMT+8 - date-format: yyyy-MM-dd HH:mm:ss resources: static-locations: classpath:/static/,classpath:/views/ diff --git a/pom.xml b/pom.xml index cfec5bc70..8f5ab5fcb 100644 --- a/pom.xml +++ b/pom.xml @@ -134,6 +134,14 @@ pom import + + + com.fasterxml.jackson.module + jackson-modules-java8 + ${jackson.modules} + pom + import +