Customizing property ordering
The order of properties appearing in the resulting JSON can also be customized using the @JsonbPropertyOrder
annotation on the Java classes. For example, we can use the lexical order, as shown in the following example:
@JsonbPropertyOrder(PropertyOrderStrategy.LEXICOGRAPHICAL) public class Movie { .... }
Upon serializing the previous object, the resulting JSON attributes will be displayed sorted in alphabetical order; you can try this yourself.
There are three available values for the property order configuration property, as shown in the following table with an explanation for each:
Order Strategy | Explanation |
| The resulting JSON attributes are not guaranteed to be in any specific order. |
| The resulting JSON attributes are shown in alphabetical order. |
| The resulting JSON attributes are shown in reverse alphabetical order. |