Man*_*sha 10 java json pretty-print jackson
我在Map对象中有数据,我想以json格式打印它.我尝试使用DefaultPrettyPrinter
mapper.writerWithDefaultPrettyPrinter().writeValue(filePath, mapObject);
Run Code Online (Sandbox Code Playgroud)
但格式不是我的预期.我得到这样的输出:
{
"arrVals" : ["value-1","value-2"]
}
Run Code Online (Sandbox Code Playgroud)
我想要这样的输出:
{
"arrVals" : [
"value-1",
"value-2"
]
}
Run Code Online (Sandbox Code Playgroud)
Mad*_*ady 16
您需要在Array Values之前缩进.您可以使用indentArraysWith方法设置Lf2SpacesIdenter对象,该对象基本上会添加换行符,后跟2个空格.这可能会解决您的问题.
DefaultPrettyPrinter pp = new DefaultPrettyPrinter();
pp.indentArraysWith(new Lf2SpacesIndenter());
mapper.writer(pp).writeValue(filePath, mapObject);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4775 次 |
| 最近记录: |