Serialize JsonNode to a very specific JSON format in Jackson

后端 未结 2 1601
南笙
南笙 2020-12-18 13:18

I have JsonNode result that I want to print out. So far, I am using:

ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeatur         


        
2条回答
  •  星月不相逢
    2020-12-18 13:33

    You can setup a custom DefaultPrettyPrinter using this:

    DefaultPrettyPrinter pp = new DefaultPrettyPrinter();
    pp.indentObjectsWith(new Lf2SpacesIndenter());
    pp.indentArraysWith(new Lf2SpacesIndenter("\r\n"));
    mapper.writer(pp).writeValue(new FileOutputStream(outputFile), resultNode);
    

    Take a look at the method provided by DefaultPrettyPrinter HERE

提交回复
热议问题