GH-677 Add spring.cloud.function.preferred-json-mapper property

Deprecate spring.http.converters.preferred-json-mapper
Resolves #677
This commit is contained in:
Oleg Zhurakousky
2021-04-09 15:50:50 +02:00
parent c93e2c3b9d
commit 376aae2d67
3 changed files with 25 additions and 3 deletions

View File

@@ -76,8 +76,11 @@ import org.springframework.util.StringUtils;
@EnableConfigurationProperties(FunctionProperties.class)
public class ContextFunctionCatalogAutoConfiguration {
@Deprecated
static final String PREFERRED_MAPPER_PROPERTY = "spring.http.converters.preferred-json-mapper";
static final String JSON_MAPPER_PROPERTY = "spring.cloud.function.preferred-json-mapper";
@Bean
public FunctionRegistry functionCatalog(List<MessageConverter> messageConverters, JsonMapper jsonMapper,
ConfigurableApplicationContext context, @Nullable FunctionInvocationHelper<Message<?>> functionInvocationHelper) {
@@ -154,7 +157,9 @@ public class ContextFunctionCatalogAutoConfiguration {
public static class JsonMapperConfiguration {
@Bean
public JsonMapper jsonMapper(ApplicationContext context) {
String preferredMapper = context.getEnvironment().getProperty(PREFERRED_MAPPER_PROPERTY);
String preferredMapper = context.getEnvironment().containsProperty(JSON_MAPPER_PROPERTY)
? context.getEnvironment().getProperty(JSON_MAPPER_PROPERTY)
: context.getEnvironment().getProperty(PREFERRED_MAPPER_PROPERTY);
if (StringUtils.hasText(preferredMapper)) {
if ("gson".equals(preferredMapper) && ClassUtils.isPresent("com.google.gson.Gson", null)) {
return gson(context);

View File

@@ -132,8 +132,13 @@ public class ContextFunctionCatalogInitializer implements ApplicationContextInit
AnnotationConfigUtils.registerAnnotationConfigProcessors(this.context);
}
ConfigurationPropertiesBindingPostProcessor.register(registry);
if (ClassUtils.isPresent("com.google.gson.Gson", null) && "gson".equals(this.context.getEnvironment()
.getProperty(ContextFunctionCatalogAutoConfiguration.PREFERRED_MAPPER_PROPERTY, "gson"))) {
String preferredMapper = context.getEnvironment().containsProperty(ContextFunctionCatalogAutoConfiguration.JSON_MAPPER_PROPERTY)
? context.getEnvironment().getProperty(ContextFunctionCatalogAutoConfiguration.JSON_MAPPER_PROPERTY)
: context.getEnvironment().getProperty(ContextFunctionCatalogAutoConfiguration.PREFERRED_MAPPER_PROPERTY);
if (ClassUtils.isPresent("com.google.gson.Gson", null) && "gson".equals(preferredMapper)) {
if (this.context.getBeanFactory().getBeanNamesForType(Gson.class, false, false).length == 0) {
this.context.registerBean(Gson.class, () -> new Gson());
}