Order of JSON objects using Jackson's ObjectMapper

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

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 { ... }

You can use @XmlAccessorType(XmlAccessType.FIELD)

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

@JsonPropertyOrder requires a new jar to be added.

Tags:

Java

Json

Jackson