Merge branch 'gh-1919' into 1.1.x

This commit is contained in:
Andy Wilkinson 2014-11-18 11:48:57 +00:00
commit 25c561313e
2 changed files with 29 additions and 0 deletions

View File

@ -90,6 +90,9 @@ public class JacksonAutoConfiguration {
objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS,
true);
}
if (this.properties.isJsonPrettyPrint()) {
objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
}
return objectMapper;
}

View File

@ -25,6 +25,7 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -35,6 +36,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.datatype.joda.JodaModule;
@ -45,6 +47,7 @@ import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.verify;
@ -101,6 +104,29 @@ public class JacksonAutoConfigurationTests {
assertEquals("{\"foo\":\"bar\"}", mapper.writeValueAsString(new Foo()));
}
@Test
public void httpMappersJsonPrettyPrintIsApplied() {
this.context.register(JacksonAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"http.mappers.json-pretty-print:true");
this.context.refresh();
ObjectMapper objectMapper = this.context.getBean(ObjectMapper.class);
assertTrue(objectMapper.getSerializationConfig().isEnabled(
SerializationFeature.INDENT_OUTPUT));
}
@Test
public void httpMappersJsonSortKeysIsApplied() {
this.context.register(JacksonAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"http.mappers.json-sort-keys:true");
this.context.refresh();
ObjectMapper objectMapper = this.context.getBean(ObjectMapper.class);
assertTrue(objectMapper.getSerializationConfig().isEnabled(
SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS));
}
@Configuration
protected static class ModulesConfig {