多亏了有用的提示,我能够配置我的所需缩进,如下所示:ObjectMapper
private static class PrettyPrinter extends DefaultPrettyPrinter {
public static final PrettyPrinter instance = new PrettyPrinter();
public PrettyPrinter() {
_arrayIndenter = Lf2SpacesIndenter.instance;
}
}
private static class Factory extends JsonFactory {
@Override
protected JsonGenerator _createGenerator(Writer out, IOContext ctxt) throws IOException {
return super._createGenerator(out, ctxt).setPrettyPrinter(PrettyPrinter.instance);
}
}
{
ObjectMapper mapper = new ObjectMapper(new Factory());
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
}