From 35b7ba5cda3f8ca2c95240d1ad86f4d82a9e8f3a Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 18 Nov 2014 13:45:09 +0000 Subject: [PATCH] Deprecate http.mappers.* properties The http.mappers.* configuration properties assumed that the mapping was JSON (on of the property names was jsonPrettyPrint) and also only exposed a small subset of the configuration options supported by Jackson (and GSON). The property names implied that it would configure all HTTP mapping, however it was ignored by GsonAutoConfiguration. This commit deprecates the support for http.mappers.* in favour of configuring Jackson or Gson instead. Jackson can be configured declaratively using the spring.jackson.* properties or programtically. Gson can be configured programatically by using a GsonBuilder to create a Gson instance with the desired configuration. gh-1946 has been opened to add support for declarative configuration of Gson. Closes gh-1945 --- .../jackson/JacksonAutoConfiguration.java | 1 + .../web/HttpMapperProperties.java | 18 ++++++++++++++++++ ...HttpMessageConvertersAutoConfiguration.java | 2 ++ .../appendix-application-properties.adoc | 4 +--- .../src/main/resources/application.properties | 2 +- 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java index 57a4e716bc..b94f74b9f2 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java @@ -63,6 +63,7 @@ import com.fasterxml.jackson.databind.SerializationFeature; */ @Configuration @ConditionalOnClass(ObjectMapper.class) +@SuppressWarnings("deprecation") public class JacksonAutoConfiguration { @Autowired diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpMapperProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpMapperProperties.java index c6b3849fc0..24353f23d5 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpMapperProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpMapperProperties.java @@ -16,9 +16,13 @@ package org.springframework.boot.autoconfigure.web; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.http.converter.HttpMessageConverter; +import com.fasterxml.jackson.databind.SerializationFeature; + /** * Configuration properties to configure {@link HttpMessageConverter}s. * @@ -27,13 +31,18 @@ import org.springframework.http.converter.HttpMessageConverter; * @author Sebastien Deleuze */ @ConfigurationProperties(prefix = "http.mappers", ignoreUnknownFields = false) +@Deprecated public class HttpMapperProperties { + private final Log logger = LogFactory.getLog(HttpMapperProperties.class); + private Boolean jsonPrettyPrint; private Boolean jsonSortKeys; public void setJsonPrettyPrint(Boolean jsonPrettyPrint) { + this.logger.warn(getDeprecationMessage("http.mappers.json-pretty-print", + SerializationFeature.INDENT_OUTPUT)); this.jsonPrettyPrint = jsonPrettyPrint; } @@ -42,6 +51,8 @@ public class HttpMapperProperties { } public void setJsonSortKeys(Boolean jsonSortKeys) { + this.logger.warn(getDeprecationMessage("http.mappers.json-sort-keys", + SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS)); this.jsonSortKeys = jsonSortKeys; } @@ -49,4 +60,11 @@ public class HttpMapperProperties { return this.jsonSortKeys; } + private String getDeprecationMessage(String property, + SerializationFeature alternativeFeature) { + return String.format("%s is deprecated. If you are using Jackson," + + " spring.jackson.serialization.%s=true should be used instead.", + property, alternativeFeature.name()); + } + } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpMessageConvertersAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpMessageConvertersAutoConfiguration.java index 42146b7e57..aa924f6319 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpMessageConvertersAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpMessageConvertersAutoConfiguration.java @@ -67,6 +67,7 @@ public class HttpMessageConvertersAutoConfiguration { @ConditionalOnClass(ObjectMapper.class) @ConditionalOnBean(ObjectMapper.class) @EnableConfigurationProperties(HttpMapperProperties.class) + @SuppressWarnings("deprecation") protected static class MappingJackson2HttpMessageConverterConfiguration { @Autowired @@ -90,6 +91,7 @@ public class HttpMessageConvertersAutoConfiguration { @ConditionalOnClass(XmlMapper.class) @ConditionalOnBean(Jackson2ObjectMapperBuilder.class) @EnableConfigurationProperties(HttpMapperProperties.class) + @SuppressWarnings("deprecation") protected static class XmlMappers { @Autowired diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 36c2dad22c..41eab46a63 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -83,9 +83,7 @@ content into your application; rather pick only the properties that you need. server.tomcat.max-threads = 0 # number of threads in protocol handler server.tomcat.uri-encoding = UTF-8 # character encoding to use for URL decoding - # SPRING MVC ({sc-spring-boot-autoconfigure}/web/HttpMapperProperties.{sc-ext}[HttpMapperProperties]) - http.mappers.json-pretty-print=false # pretty print JSON - http.mappers.json-sort-keys=false # sort keys + # SPRING MVC ({sc-spring-boot-autoconfigure}/web/WebMvcProperties.{sc-ext}[WebMvcProperties]) spring.mvc.locale= # set fixed locale, e.g. en_UK spring.mvc.date-format= # set fixed date format, e.g. dd/MM/yyyy spring.mvc.message-codes-resolver-format= # PREFIX_ERROR_CODE / POSTFIX_ERROR_CODE diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-actuator/src/main/resources/application.properties index 61ed523499..9eb7e230f8 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-actuator/src/main/resources/application.properties @@ -8,7 +8,7 @@ server.tomcat.access_log_enabled: true server.tomcat.access_log_pattern: %h %t "%r" %s %b security.require_ssl: false service.name: Phil -#http.mappers.json_pretty_print: true +#spring.jackson.serialization.INDENT_OUTPUT: true shell.ssh.enabled: true shell.ssh.port: 2222 #shell.telnet.enabled: false