Pretty print option for Jackson converter and view
Jackson serialization supports pretty printing. Usually it's enabled by invoking ObjectMapper.configure(..), which is not convenient for apps with XML configuration. The Jackson HttpMessageConverter and View now both have a prettyPrint property. A second more serious issue is documented here: https://github.com/FasterXML/jackson-databind/issues/12 The workaround discussed at the above link has been implemented. Issue: SPR-7201
This commit is contained in:
@@ -37,6 +37,7 @@ import org.mozilla.javascript.ContextFactory;
|
||||
import org.mozilla.javascript.ScriptableObject;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.validation.BindingResult;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
@@ -143,6 +144,20 @@ public class MappingJackson2JsonViewTest {
|
||||
validateResult();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void renderWithPrettyPrint() throws Exception {
|
||||
|
||||
ModelMap model = new ModelMap("foo", new TestBeanSimple());
|
||||
|
||||
view.setPrettyPrint(true);
|
||||
view.render(model, request, response);
|
||||
|
||||
String result = response.getContentAsString();
|
||||
assertTrue("Pretty printing not applied:\n" + result, result.startsWith("{\n \"foo\" : {\n "));
|
||||
|
||||
validateResult();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void renderSimpleBeanPrefixed() throws Exception {
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ import org.codehaus.jackson.map.SerializerFactory;
|
||||
import org.codehaus.jackson.map.SerializerProvider;
|
||||
import org.codehaus.jackson.map.annotate.JsonSerialize;
|
||||
import org.codehaus.jackson.map.ser.BeanSerializerFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mozilla.javascript.Context;
|
||||
@@ -46,6 +45,7 @@ import org.mozilla.javascript.ContextFactory;
|
||||
import org.mozilla.javascript.ScriptableObject;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.validation.BindingResult;
|
||||
|
||||
/**
|
||||
@@ -137,6 +137,20 @@ public class MappingJacksonJsonViewTest {
|
||||
validateResult();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void renderWithPrettyPrint() throws Exception {
|
||||
|
||||
ModelMap model = new ModelMap("foo", new TestBeanSimple());
|
||||
|
||||
view.setPrettyPrint(true);
|
||||
view.render(model, request, response);
|
||||
|
||||
String result = response.getContentAsString();
|
||||
assertTrue("Pretty printing not applied:\n" + result, result.startsWith("{\n \"foo\" : {\n "));
|
||||
|
||||
validateResult();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void renderSimpleBeanPrefixed() throws Exception {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user