当我们使用Jackson和SerializationFeature时
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationConfig.Feature.INDENT_OUTPUT);
以下输出翻译
{"employee1":{"id":"1","firstName":"Ranga","lastName":"Reddy"},"employee2":{"id":"2","firstName":"Raja","lastName":"Reddy"}}
到
{
"employee1" : {
"id" : "1",
"firstName" : "Ranga",
"lastName" : "Reddy"
},
"employee2" : {
"id" : "2",
"firstName" : "Raja",
"lastName" : "Reddy"
}
}
但我想要这样的输出(属性名称和值之间应该有相同的空格)
{
"employee1" : {
"id" : "1",
"firstName" : "Ranga",
"lastName" : "Reddy"
},
"employee2" : {
"id" : "2",
"firstName" : "Raja",
"lastName" : "Reddy"
}
}
输出在上面生成,输出更具可读性。如何实现这个。
答案 0 :(得分:0)
使用以下代码: -
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);