fix: 优化object mapper项目配置注入
This commit is contained in:
parent
f4c0a4e678
commit
210fd09600
@ -1,5 +1,6 @@
|
|||||||
package group.flyfish.rest.configuration;
|
package group.flyfish.rest.configuration;
|
||||||
|
|
||||||
|
import group.flyfish.rest.configuration.configure.RestObjectMapperProvider;
|
||||||
import group.flyfish.rest.core.factory.DefaultHttpClientProvider;
|
import group.flyfish.rest.core.factory.DefaultHttpClientProvider;
|
||||||
import group.flyfish.rest.core.factory.HttpClientFactoryBean;
|
import group.flyfish.rest.core.factory.HttpClientFactoryBean;
|
||||||
import group.flyfish.rest.core.factory.HttpClientProvider;
|
import group.flyfish.rest.core.factory.HttpClientProvider;
|
||||||
@ -11,6 +12,7 @@ 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 group.flyfish.rest.utils.JacksonUtil;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
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;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@ -98,7 +100,8 @@ public class RestClientConfiguration {
|
|||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public JacksonUtil restJacksonUtil() {
|
public JacksonUtil restJacksonUtil(ObjectProvider<RestObjectMapperProvider> provider) {
|
||||||
|
provider.ifAvailable(bean -> JacksonUtil.setObjectMapper(bean.provide()));
|
||||||
return new JacksonUtil();
|
return new JacksonUtil();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
package group.flyfish.rest.configuration.configure;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* object mapper配置器
|
||||||
|
*
|
||||||
|
* @author wangyu
|
||||||
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface RestObjectMapperProvider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提供项目级别的object mapper
|
||||||
|
*
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
ObjectMapper provide();
|
||||||
|
}
|
@ -66,6 +66,15 @@ public final class JacksonUtil {
|
|||||||
mapper.configure(JsonGenerator.Feature.ESCAPE_NON_ASCII, true);
|
mapper.configure(JsonGenerator.Feature.ESCAPE_NON_ASCII, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置jackson
|
||||||
|
*
|
||||||
|
* @param objectMapper 映射器
|
||||||
|
*/
|
||||||
|
public static void setObjectMapper(ObjectMapper objectMapper) {
|
||||||
|
JacksonUtil.mapper = objectMapper;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修复不同环境下统一序列化表现
|
* 修复不同环境下统一序列化表现
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user