在使用Spring MVC开发睡觉服务时,我想让JSON在开发时"打印得很好",但在生产中是正常的(减少了空格).
在使用Spring MVC开发睡觉服务时,我想让JSON在开发时"打印得很好",但在生产中是正常的(减少了空格).
If you are using Spring Boot 1.2 or later the simple solution is to add
spring.jackson.serialization.INDENT_OUTPUT=true
to the application.properties
file. This assumes that you are using Jackson for serialization.
如果您使用的是早期版本的Spring Boot,则可以添加
http.mappers.json-pretty-print=true
This solution still works with Spring Boot 1.2 but it is deprecated and will eventually be removed entirely. You will get a deprecation warning in the log at startup time.
(使用spring-boot-starter-web
进行测试)