`SORT_PROPERTIES_ALPHABETICALLY` is case-sensitive: capital letters sorted before lower-case
See original GitHub issueBackground: For signature verification, I need all fields sorted in absolute order from server to client.
Here is the basic code
ObjectMapper mapper = new ObjectMapper();
mapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS"));
String bodyString = mapper.writeValueAsString(data);
Inside my custom class, there is one boolean field called topped, but it seems not placed in right place after sorting. For example:
{“chatPair”:{“createdAt”:“2021-03-23 16:53:43 825”,“id”:19,“pairUser”:{“createdAt”:“2021-03-23 16:53:43 875”,“fromUserId”:4,“id”:“6059ac979aad5b48e05dfaa2”,“muted”:false,“pairId”:19,“relationType0”:“Unknown”,“relationType1”:“Unknown”,“screened”:false,“toUserId”:5,“topped”:false,“updatedAt”:“2021-03-23 16:53:43 875”},“updatedAt”:“2021-03-23 16:53:43 709”}}
field topped is supposed to sit before field toUserId. Field topped was declared as “boolean topped = false;” in my class, and no @JsonPropertyOrder set.
Version information 2.10.2
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (5 by maintainers)
Top GitHub Comments
Sorry, no, did not mean that there was any setting that would change this. Case-insensitive handling applies to mapping of external names to internal property names, but is not used for sorting currently.
@FelixVaughan01 Yes, I think that if a new on/off feature is needed – which I think is true since there will be behavioral change – it should be added as
MapperFeature
. This because although this mostly/only affects Serialization side of things, it is not something that can likely be changed on per-call basis (since sorting order is calculated when creating serializers, which are then cached; and not dynamically as-needed).