-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@JsonPropertyOrder(alphabetic = true)
does not include @JsonAnyGetter
#518
Comments
Hmmmh. True, sorting does not apply there, nor is it easy to implement the way sorting is implemented, as it applies to property accessor objects (name of which are known statically), and "any getter" applies to fully dynamic names. |
+1 for this. Would also be happy to have the default behavior for anygetter either be alphabetical or have an option for that. |
Adding sorting just for |
+1 for this. |
@JsonPropertyOrder(alphabetic = true)
does not include @JsonAnyGetter
+1 for this also, however would like to be able to specify the property order explicitly (rather than alphabetic). Would really like to specify the location of the @JsonAnyGetter property and have all of it's fields all serialised in that location. eg.
|
Dumb work-around if it fits your needs: You can use a TreeMap - the default comparator sorts keys lexicographically. You can use a custom comparator to sort keys differently. |
Case 1 : Allow
|
Case 2 : any-properties added during runtime via
|
Just to make it clear: at first, I only propose that any-properties are sorted "as a block" and do not mix otherwise with regular properties. I also think that any-properties as a set/block are to be serialized using order they are iterated in from containing I hope above makes sense wrt what I think should be done? (aside from question of whether that is what should be done :) ). |
This would be covered by Case 1, and...
... by Case 2. By NOT implementing Case 2, proposal would be satisfied I guess. |
The JsonPropertyOrder annotation does only sort the explicitly defined properties of an object, additional properties which may be stored using the JsonAnySetter/JsonAnyGetter annotations are not taken into account and just appended at the end.
This is not a bug as the order of properties in a JSON object should never be of any importance but when dumping objects into logs or diffing JSON outputs in unit tests it would be nice if the ordering would be alphabetic for all properties.
(if a TreeMap is used for the additionalProperties at least they for themselves are orderd alphabetic too)
The text was updated successfully, but these errors were encountered: