fix: 优化object mapper项目配置注入
This commit is contained in:
parent
f19c8b550c
commit
f4c0a4e678
4
pom.xml
4
pom.xml
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
<groupId>group.flyfish</groupId>
|
<groupId>group.flyfish</groupId>
|
||||||
<artifactId>rest-proxy</artifactId>
|
<artifactId>rest-proxy</artifactId>
|
||||||
<version>1.1.8</version>
|
<version>1.1.9</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
@ -22,7 +22,7 @@
|
|||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<commons-collection.version>4.4</commons-collection.version>
|
<commons-collection.version>4.4</commons-collection.version>
|
||||||
<commons.lang.version>2.6</commons.lang.version>
|
<commons.lang.version>2.6</commons.lang.version>
|
||||||
<sdk.version>1.1.8</sdk.version>
|
<sdk.version>1.1.9</sdk.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>group.flyfish</groupId>
|
<groupId>group.flyfish</groupId>
|
||||||
<artifactId>rest-proxy</artifactId>
|
<artifactId>rest-proxy</artifactId>
|
||||||
<version>1.1.8</version>
|
<version>1.1.9</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>group.flyfish</groupId>
|
<groupId>group.flyfish</groupId>
|
||||||
<artifactId>rest-proxy</artifactId>
|
<artifactId>rest-proxy</artifactId>
|
||||||
<version>1.1.8</version>
|
<version>1.1.9</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -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.RestArgumentResolverComposite;
|
||||||
import group.flyfish.rest.registry.proxy.support.resolvers.*;
|
import group.flyfish.rest.registry.proxy.support.resolvers.*;
|
||||||
import group.flyfish.rest.utils.DataUtils;
|
import group.flyfish.rest.utils.DataUtils;
|
||||||
|
import group.flyfish.rest.utils.JacksonUtil;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
@ -90,4 +91,14 @@ public class RestClientConfiguration {
|
|||||||
);
|
);
|
||||||
return new RestArgumentResolverComposite(resolvers);
|
return new RestArgumentResolverComposite(resolvers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新原生的jackson object mapper
|
||||||
|
*
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public JacksonUtil restJacksonUtil() {
|
||||||
|
return new JacksonUtil();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,8 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
|
|||||||
import com.fasterxml.jackson.databind.JavaType;
|
import com.fasterxml.jackson.databind.JavaType;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
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.io.IOException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
@ -24,7 +26,7 @@ import java.util.Optional;
|
|||||||
*/
|
*/
|
||||||
public final class JacksonUtil {
|
public final class JacksonUtil {
|
||||||
|
|
||||||
private static final ObjectMapper mapper = new ObjectMapper();
|
private static ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// =========================================================================
|
// =========================================================================
|
||||||
@ -64,6 +66,16 @@ public final class JacksonUtil {
|
|||||||
mapper.configure(JsonGenerator.Feature.ESCAPE_NON_ASCII, true);
|
mapper.configure(JsonGenerator.Feature.ESCAPE_NON_ASCII, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修复不同环境下统一序列化表现
|
||||||
|
*
|
||||||
|
* @param objectMappers jackson om
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
public void setObjectMapper(ObjectProvider<ObjectMapper> objectMappers) {
|
||||||
|
objectMappers.ifAvailable(om -> mapper = om);
|
||||||
|
}
|
||||||
|
|
||||||
public static <T> T fromJson(final String json) {
|
public static <T> T fromJson(final String json) {
|
||||||
return readValue(json, new TypeReference<T>() {
|
return readValue(json, new TypeReference<T>() {
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user