|
|
|
@ -29,6 +29,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
|
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.context.annotation.Primary;
|
|
|
|
@ -42,6 +44,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
* {@link EnableAutoConfiguration Auto-configuration} for {@link HttpMessageConverter}s.
|
|
|
|
|
*
|
|
|
|
|
* @author Dave Syer
|
|
|
|
|
* @author Christian Dupuis
|
|
|
|
|
*/
|
|
|
|
|
@Configuration
|
|
|
|
|
@ConditionalOnClass(HttpMessageConverter.class)
|
|
|
|
@ -60,8 +63,12 @@ public class HttpMessageConvertersAutoConfiguration {
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
@ConditionalOnClass(ObjectMapper.class)
|
|
|
|
|
@EnableConfigurationProperties(ObjectMappersProperties.class)
|
|
|
|
|
protected static class ObjectMappers {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ObjectMappersProperties properties = new ObjectMappersProperties();
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ListableBeanFactory beanFactory;
|
|
|
|
|
|
|
|
|
@ -90,9 +97,27 @@ public class HttpMessageConvertersAutoConfiguration {
|
|
|
|
|
ObjectMapper objectMapper) {
|
|
|
|
|
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
|
|
|
|
|
converter.setObjectMapper(objectMapper);
|
|
|
|
|
converter.setPrettyPrint(this.properties.isJsonPrettyPrint());
|
|
|
|
|
return converter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@link ConfigurationProperties} to configure {@link HttpMessageConverter}s.
|
|
|
|
|
*/
|
|
|
|
|
@ConfigurationProperties(name = "http.mappers", ignoreUnknownFields = false)
|
|
|
|
|
public static class ObjectMappersProperties {
|
|
|
|
|
|
|
|
|
|
private boolean jsonPrettyPrint = false;
|
|
|
|
|
|
|
|
|
|
public void setJsonPrettyPrint(boolean jsonPrettyPrint) {
|
|
|
|
|
this.jsonPrettyPrint = jsonPrettyPrint;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isJsonPrettyPrint() {
|
|
|
|
|
return this.jsonPrettyPrint;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|