|
25 | 25 | import org.junit.Test; |
26 | 26 | import org.mockito.Mockito; |
27 | 27 | import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; |
| 28 | +import org.springframework.boot.test.EnvironmentTestUtils; |
28 | 29 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
29 | 30 | import org.springframework.context.annotation.Bean; |
30 | 31 | import org.springframework.context.annotation.Configuration; |
|
35 | 36 | import com.fasterxml.jackson.databind.JsonSerializer; |
36 | 37 | import com.fasterxml.jackson.databind.Module; |
37 | 38 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 39 | +import com.fasterxml.jackson.databind.SerializationFeature; |
38 | 40 | import com.fasterxml.jackson.databind.SerializerProvider; |
39 | 41 | import com.fasterxml.jackson.databind.module.SimpleModule; |
40 | 42 | import com.fasterxml.jackson.datatype.joda.JodaModule; |
|
45 | 47 | import static org.hamcrest.Matchers.is; |
46 | 48 | import static org.junit.Assert.assertEquals; |
47 | 49 | import static org.junit.Assert.assertThat; |
| 50 | +import static org.junit.Assert.assertTrue; |
48 | 51 | import static org.mockito.Matchers.argThat; |
49 | 52 | import static org.mockito.Mockito.verify; |
50 | 53 |
|
@@ -101,6 +104,29 @@ public void doubleModuleRegistration() throws Exception { |
101 | 104 | assertEquals("{\"foo\":\"bar\"}", mapper.writeValueAsString(new Foo())); |
102 | 105 | } |
103 | 106 |
|
| 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 | + |
104 | 130 | @Configuration |
105 | 131 | protected static class ModulesConfig { |
106 | 132 |
|
|
0 commit comments