Order of JSON objects using Jackson's ObjectMapper

后端 未结 3 2049
时光取名叫无心
时光取名叫无心 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:34

    You can use @XmlAccessorType(XmlAccessType.FIELD)

    @XmlType(name = "response", propOrder = { "prop1", "prop2",
            "prop3", "prop4", "prop5", "prop6" }).
    

    @JsonPropertyOrder requires a new jar to be added.

    0 讨论(0)
  • 2020-12-02 14:37
    @JsonPropertyOrder({ "id", "label", "target", "source", "attributes" })
    public class Relation { ... }
    
    0 讨论(0)
  • 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 { ... }
    
    0 讨论(0)
提交回复
热议问题