Java 为什么DefaultIndenter().withIndent(“缩进”)的缩进量比我预期的要多而少?
我有一些代码,我希望在.withIndent()中,将JSON数组的缩进更改为“”中包含的每个空格一个空格。arrayIndenter的行为与我预期的一样,但是当我向objectIndenter添加或删除一个空格时,它会添加或删除两个空格Java 为什么DefaultIndenter().withIndent(“缩进”)的缩进量比我预期的要多而少?,java,json,jackson,Java,Json,Jackson,我有一些代码,我希望在.withIndent()中,将JSON数组的缩进更改为“”中包含的每个空格一个空格。arrayIndenter的行为与我预期的一样,但是当我向objectIndenter添加或删除一个空格时,它会添加或删除两个空格 ObjectMapper mapper = new ObjectMapper(); DefaultPrettyPrinter.Indenter objectIndenter = new Defaul
ObjectMapper mapper = new ObjectMapper();
DefaultPrettyPrinter.Indenter objectIndenter =
new DefaultIndenter().withIndent(" ");
DefaultPrettyPrinter.Indenter arrayIndenter =
new DefaultIndenter().withIndent(" ");
DefaultPrettyPrinter printer = new DefaultPrettyPrinter();
printer.indentObjectsWith(objectIndenter);
printer.indentArraysWith(arrayIndenter);
mapper.writer(printer).writeValue(new File(myPath), myJSON);
我试图复制以下的精确缩进:
[
{
"thing1" : "thing1",
"thing2" : "thing2",
"thing3" : "thing3",
"thing4" : "thing4",
"thing5" : "thing5",
"thing6" : [
"thing6"
]
},
{
"thing1" : "thing1",
"thing2" : "thing2",
"thing3" : "thing3",
"thing4" : "thing4",
"thing5" : "thing5",
"thing6" : [
"thing6"
]
}
]
但是,当我向ObjectIndender添加一个空格时,它会超出或超出1列。例如,我需要“in”thing1从第8列开始,但我只能从第7列或第9列开始,因为在缩进中删除/添加空格实际上会增加两个空格