mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
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
This commit is contained in:
parent
6cfd6cad64
commit
35b7ba5cda
@ -63,6 +63,7 @@ import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(ObjectMapper.class)
|
||||
@SuppressWarnings("deprecation")
|
||||
public class JacksonAutoConfiguration {
|
||||
|
||||
@Autowired
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user