在使用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进行测试)

Json相关问答推荐

如何在数组抖动中按值分组

Azure Data Factory JSON输出格式问题

解析JSON说函数parse_json不存在?

PowerShell女士:如何处理json对象?

错误:在 NX 工作区中找不到模块../swagger.json

将不带正文的 CURL POST 转换为 RESTRequest Delphi 代码 / 为 Dropbox API /get_current_account 端点编写 Delphi 代码

根据值过滤输入的JSON并使用它准备预期的输出

如何使用SQLite Trigger将JSON对象数组转换为新记录?

使用 jq 从字符串列表开始创建对象

通过sql查询读取嵌套Json

字典和对象的模型创建问题

反序列化大型 json 对象的 JsonMaxLength 异常

对象序列化为 JSON(使用 Gson).如何在 UpperCamelCase 中设置字段名称?

使用 ajax 将 JSON 发送到 PHP

Json.NET 是否缓存类型的序列化信息?

使用 JSON.Net 的 C# 到 JSON 序列化

从 Json 对象 Android 中获取字符串值

为什么 JavaScript 的 eval 需要括号来判断 JSON 数据?

运算符不存在:json = json

处理 HTTP 请求正文中的可选 JSON 字段