Order of JSON objects using Jackson's ObjectMapper

后端 未结 3 2072
时光取名叫无心
时光取名叫无心 2020-12-02 14:17

I\'m using ObjectMapper to do my java-json mapping.

ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
ow.writeValue(new File         


        
3条回答
  •  情话喂你
    2020-12-02 14:40

    Do you know there is a convenient way to specify alphabetic ordering?

    @JsonPropertyOrder(alphabetic = true)
    public class Relation { ... }
    

    If you have specific requirements, here how you configure custom ordering:

    @JsonPropertyOrder({ "id", "label", "target", "source", "attributes" })
    public class Relation { ... }
    

提交回复
热议问题