question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`SORT_PROPERTIES_ALPHABETICALLY` is case-sensitive: capital letters sorted before lower-case

See original GitHub issue

Background: 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:closed
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cowtowncodercommented, Mar 24, 2021

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.

0reactions
cowtowncodercommented, Oct 10, 2022

@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).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sort records in case-sensitive order - Microsoft Support
Sorting on the basis of the ASCII values differentiates the uppercase letters from the lowercase letters, and results in a case-sensitive order.
Read more >
Sort in alphabetical order with lowercase before uppercase?
Note: This answer focuses on the general case of sorting entire strings (by all of their characters, not just by the first one)....
Read more >
Does case matter when reading and sorting a list of items?
Capitalization frequently matters for sorting algorithms, ... first portion was for upper-case letters / locate the end of uppercase list.
Read more >
Python List sort() Method - Learn By Example
Case -insensitive Sorting. By default, the sort() method sorts the list in ASCIIbetical order rather than actual alphabetical order. This means uppercase letters...
Read more >
Case-sensitivity quirks with Velocity sorts - Marketing Nation
By “alphabetically,” those folks mean case-insensitive sort order, where uppercase/lowercase pairs (in the local language) are treated as ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found