Commit 35b7ba5c authored by Andy Wilkinson's avatar Andy Wilkinson

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
parent 6cfd6cad
...@@ -63,6 +63,7 @@ import com.fasterxml.jackson.databind.SerializationFeature; ...@@ -63,6 +63,7 @@ import com.fasterxml.jackson.databind.SerializationFeature;
*/ */
@Configuration @Configuration
@ConditionalOnClass(ObjectMapper.class) @ConditionalOnClass(ObjectMapper.class)
@SuppressWarnings("deprecation")
public class JacksonAutoConfiguration { public class JacksonAutoConfiguration {
@Autowired @Autowired
......
...@@ -16,9 +16,13 @@ ...@@ -16,9 +16,13 @@
package org.springframework.boot.autoconfigure.web; 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.boot.context.properties.ConfigurationProperties;
import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter;
import com.fasterxml.jackson.databind.SerializationFeature;
/** /**
* Configuration properties to configure {@link HttpMessageConverter}s. * Configuration properties to configure {@link HttpMessageConverter}s.
* *
...@@ -27,13 +31,18 @@ import org.springframework.http.converter.HttpMessageConverter; ...@@ -27,13 +31,18 @@ import org.springframework.http.converter.HttpMessageConverter;
* @author Sebastien Deleuze * @author Sebastien Deleuze
*/ */
@ConfigurationProperties(prefix = "http.mappers", ignoreUnknownFields = false) @ConfigurationProperties(prefix = "http.mappers", ignoreUnknownFields = false)
@Deprecated
public class HttpMapperProperties { public class HttpMapperProperties {
private final Log logger = LogFactory.getLog(HttpMapperProperties.class);
private Boolean jsonPrettyPrint; private Boolean jsonPrettyPrint;
private Boolean jsonSortKeys; private Boolean jsonSortKeys;
public void setJsonPrettyPrint(Boolean jsonPrettyPrint) { public void setJsonPrettyPrint(Boolean jsonPrettyPrint) {
this.logger.warn(getDeprecationMessage("http.mappers.json-pretty-print",
SerializationFeature.INDENT_OUTPUT));
this.jsonPrettyPrint = jsonPrettyPrint; this.jsonPrettyPrint = jsonPrettyPrint;
} }
...@@ -42,6 +51,8 @@ public class HttpMapperProperties { ...@@ -42,6 +51,8 @@ public class HttpMapperProperties {
} }
public void setJsonSortKeys(Boolean jsonSortKeys) { public void setJsonSortKeys(Boolean jsonSortKeys) {
this.logger.warn(getDeprecationMessage("http.mappers.json-sort-keys",
SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS));
this.jsonSortKeys = jsonSortKeys; this.jsonSortKeys = jsonSortKeys;
} }
...@@ -49,4 +60,11 @@ public class HttpMapperProperties { ...@@ -49,4 +60,11 @@ public class HttpMapperProperties {
return this.jsonSortKeys; 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());
}
} }
...@@ -67,6 +67,7 @@ public class HttpMessageConvertersAutoConfiguration { ...@@ -67,6 +67,7 @@ public class HttpMessageConvertersAutoConfiguration {
@ConditionalOnClass(ObjectMapper.class) @ConditionalOnClass(ObjectMapper.class)
@ConditionalOnBean(ObjectMapper.class) @ConditionalOnBean(ObjectMapper.class)
@EnableConfigurationProperties(HttpMapperProperties.class) @EnableConfigurationProperties(HttpMapperProperties.class)
@SuppressWarnings("deprecation")
protected static class MappingJackson2HttpMessageConverterConfiguration { protected static class MappingJackson2HttpMessageConverterConfiguration {
@Autowired @Autowired
...@@ -90,6 +91,7 @@ public class HttpMessageConvertersAutoConfiguration { ...@@ -90,6 +91,7 @@ public class HttpMessageConvertersAutoConfiguration {
@ConditionalOnClass(XmlMapper.class) @ConditionalOnClass(XmlMapper.class)
@ConditionalOnBean(Jackson2ObjectMapperBuilder.class) @ConditionalOnBean(Jackson2ObjectMapperBuilder.class)
@EnableConfigurationProperties(HttpMapperProperties.class) @EnableConfigurationProperties(HttpMapperProperties.class)
@SuppressWarnings("deprecation")
protected static class XmlMappers { protected static class XmlMappers {
@Autowired @Autowired
......
...@@ -83,9 +83,7 @@ content into your application; rather pick only the properties that you need. ...@@ -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.max-threads = 0 # number of threads in protocol handler
server.tomcat.uri-encoding = UTF-8 # character encoding to use for URL decoding server.tomcat.uri-encoding = UTF-8 # character encoding to use for URL decoding
# SPRING MVC ({sc-spring-boot-autoconfigure}/web/HttpMapperProperties.{sc-ext}[HttpMapperProperties]) # SPRING MVC ({sc-spring-boot-autoconfigure}/web/WebMvcProperties.{sc-ext}[WebMvcProperties])
http.mappers.json-pretty-print=false # pretty print JSON
http.mappers.json-sort-keys=false # sort keys
spring.mvc.locale= # set fixed locale, e.g. en_UK 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.date-format= # set fixed date format, e.g. dd/MM/yyyy
spring.mvc.message-codes-resolver-format= # PREFIX_ERROR_CODE / POSTFIX_ERROR_CODE spring.mvc.message-codes-resolver-format= # PREFIX_ERROR_CODE / POSTFIX_ERROR_CODE
......
...@@ -8,7 +8,7 @@ server.tomcat.access_log_enabled: true ...@@ -8,7 +8,7 @@ server.tomcat.access_log_enabled: true
server.tomcat.access_log_pattern: %h %t "%r" %s %b server.tomcat.access_log_pattern: %h %t "%r" %s %b
security.require_ssl: false security.require_ssl: false
service.name: Phil service.name: Phil
#http.mappers.json_pretty_print: true #spring.jackson.serialization.INDENT_OUTPUT: true
shell.ssh.enabled: true shell.ssh.enabled: true
shell.ssh.port: 2222 shell.ssh.port: 2222
#shell.telnet.enabled: false #shell.telnet.enabled: false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment