Depending on which version of Spring you are using MappingJacksonHttpMessageConverter , you must have a boolean property called prettyPrint to configure the printer when serializing JSON.
So this XML configuration should do the trick (if you are using the latest version of Spring 3)
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="messageConverters"> <list> <ref bean="jsonConverter" /> </list> </property> </bean> <bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> <property name="supportedMediaTypes" value="application/json" /> <property name="objectMapper" ref="jacksonObjectMapper" /> <property name="prettyPrint" value="false" /> </bean>
You can see the related commit on github, representing the property. And the trunk version of the class that includes this property. Lastly, this is a Spring Jira SPR-7201 issue related to a previous commit.
Or you could try upgrading your version of Jackson to a later version that includes the useDefaultPrettyPrinter and setPrettyPrinter methods mentioned by Alexander Ryzhov
source share