Skip to content

Commit 25c5613

Browse files
committed
Merge branch 'spring-projectsgh-1919' into 1.1.x
2 parents 33dfab0 + 9eae299 commit 25c5613

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java

+3
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ public ObjectMapper jacksonObjectMapper() {
9090
objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS,
9191
true);
9292
}
93+
if (this.properties.isJsonPrettyPrint()) {
94+
objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
95+
}
9396
return objectMapper;
9497
}
9598

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java

+26
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.junit.Test;
2626
import org.mockito.Mockito;
2727
import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration;
28+
import org.springframework.boot.test.EnvironmentTestUtils;
2829
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
2930
import org.springframework.context.annotation.Bean;
3031
import org.springframework.context.annotation.Configuration;
@@ -35,6 +36,7 @@
3536
import com.fasterxml.jackson.databind.JsonSerializer;
3637
import com.fasterxml.jackson.databind.Module;
3738
import com.fasterxml.jackson.databind.ObjectMapper;
39+
import com.fasterxml.jackson.databind.SerializationFeature;
3840
import com.fasterxml.jackson.databind.SerializerProvider;
3941
import com.fasterxml.jackson.databind.module.SimpleModule;
4042
import com.fasterxml.jackson.datatype.joda.JodaModule;
@@ -45,6 +47,7 @@
4547
import static org.hamcrest.Matchers.is;
4648
import static org.junit.Assert.assertEquals;
4749
import static org.junit.Assert.assertThat;
50+
import static org.junit.Assert.assertTrue;
4851
import static org.mockito.Matchers.argThat;
4952
import static org.mockito.Mockito.verify;
5053

@@ -101,6 +104,29 @@ public void doubleModuleRegistration() throws Exception {
101104
assertEquals("{\"foo\":\"bar\"}", mapper.writeValueAsString(new Foo()));
102105
}
103106

107+
@Test
108+
public void httpMappersJsonPrettyPrintIsApplied() {
109+
this.context.register(JacksonAutoConfiguration.class);
110+
EnvironmentTestUtils.addEnvironment(this.context,
111+
"http.mappers.json-pretty-print:true");
112+
this.context.refresh();
113+
ObjectMapper objectMapper = this.context.getBean(ObjectMapper.class);
114+
assertTrue(objectMapper.getSerializationConfig().isEnabled(
115+
SerializationFeature.INDENT_OUTPUT));
116+
}
117+
118+
@Test
119+
public void httpMappersJsonSortKeysIsApplied() {
120+
this.context.register(JacksonAutoConfiguration.class);
121+
EnvironmentTestUtils.addEnvironment(this.context,
122+
"http.mappers.json-sort-keys:true");
123+
this.context.refresh();
124+
ObjectMapper objectMapper = this.context.getBean(ObjectMapper.class);
125+
assertTrue(objectMapper.getSerializationConfig().isEnabled(
126+
SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS));
127+
128+
}
129+
104130
@Configuration
105131
protected static class ModulesConfig {
106132

0 commit comments

Comments
 (0)