From f4c0a4e678d09fe76232188e8c199c50bf8b920e Mon Sep 17 00:00:00 2001 From: wangyu <727842003@qq.com> Date: Mon, 27 May 2024 17:45:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96object=20mapper?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E9=85=8D=E7=BD=AE=E6=B3=A8=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 4 ++-- rest-proxy-api/pom.xml | 2 +- rest-proxy-core/pom.xml | 2 +- .../configuration/RestClientConfiguration.java | 11 +++++++++++ .../java/group/flyfish/rest/utils/JacksonUtil.java | 14 +++++++++++++- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 249210a..41ca5ca 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ group.flyfish rest-proxy - 1.1.8 + 1.1.9 8 @@ -22,7 +22,7 @@ 1.8 4.4 2.6 - 1.1.8 + 1.1.9 pom diff --git a/rest-proxy-api/pom.xml b/rest-proxy-api/pom.xml index 7b51411..0414bc7 100644 --- a/rest-proxy-api/pom.xml +++ b/rest-proxy-api/pom.xml @@ -5,7 +5,7 @@ group.flyfish rest-proxy - 1.1.8 + 1.1.9 4.0.0 diff --git a/rest-proxy-core/pom.xml b/rest-proxy-core/pom.xml index ef428cd..467e566 100644 --- a/rest-proxy-core/pom.xml +++ b/rest-proxy-core/pom.xml @@ -5,7 +5,7 @@ group.flyfish rest-proxy - 1.1.8 + 1.1.9 4.0.0 diff --git a/rest-proxy-core/src/main/java/group/flyfish/rest/configuration/RestClientConfiguration.java b/rest-proxy-core/src/main/java/group/flyfish/rest/configuration/RestClientConfiguration.java index c7bd60f..5efc682 100644 --- a/rest-proxy-core/src/main/java/group/flyfish/rest/configuration/RestClientConfiguration.java +++ b/rest-proxy-core/src/main/java/group/flyfish/rest/configuration/RestClientConfiguration.java @@ -9,6 +9,7 @@ import group.flyfish.rest.registry.proxy.support.RestArgumentResolver; import group.flyfish.rest.registry.proxy.support.RestArgumentResolverComposite; import group.flyfish.rest.registry.proxy.support.resolvers.*; import group.flyfish.rest.utils.DataUtils; +import group.flyfish.rest.utils.JacksonUtil; import org.apache.http.impl.client.CloseableHttpClient; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -90,4 +91,14 @@ public class RestClientConfiguration { ); return new RestArgumentResolverComposite(resolvers); } + + /** + * 更新原生的jackson object mapper + * + * @return 结果 + */ + @Bean + public JacksonUtil restJacksonUtil() { + return new JacksonUtil(); + } } diff --git a/rest-proxy-core/src/main/java/group/flyfish/rest/utils/JacksonUtil.java b/rest-proxy-core/src/main/java/group/flyfish/rest/utils/JacksonUtil.java index 5e8c1e1..714f264 100644 --- a/rest-proxy-core/src/main/java/group/flyfish/rest/utils/JacksonUtil.java +++ b/rest-proxy-core/src/main/java/group/flyfish/rest/utils/JacksonUtil.java @@ -9,6 +9,8 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; +import org.springframework.beans.factory.ObjectProvider; +import org.springframework.beans.factory.annotation.Autowired; import java.io.IOException; import java.text.SimpleDateFormat; @@ -24,7 +26,7 @@ import java.util.Optional; */ public final class JacksonUtil { - private static final ObjectMapper mapper = new ObjectMapper(); + private static ObjectMapper mapper = new ObjectMapper(); static { // ========================================================================= @@ -64,6 +66,16 @@ public final class JacksonUtil { mapper.configure(JsonGenerator.Feature.ESCAPE_NON_ASCII, true); } + /** + * 修复不同环境下统一序列化表现 + * + * @param objectMappers jackson om + */ + @Autowired + public void setObjectMapper(ObjectProvider objectMappers) { + objectMappers.ifAvailable(om -> mapper = om); + } + public static T fromJson(final String json) { return readValue(json, new TypeReference() { });