jakartaee / jakartaee/jsonb-api
[Clarification] should PropertyOrderStrategy also get applied to Map and Set fields?
- Dominant language
- Java
- Stars
- 95
- Forks
- 41
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 35
Description
We've got a user question in Johnzon whether setting PropertyOrderStrategy should end up sorting Map and Set fields as well.
My personal interpretation from reading the spec is that it only applies to class fields (JSON-B properties).
```
public class Bla {
private String b = "bla;
private Map a = new HashMap<>();
...
a.put("x", 4);
a.put("y", 5;
...
}
```
Might end up as
```
{"a":{"y":5,"x":4},"b":"bla"}
```
Note that while the field members are sorted (a,b) the Map values are not.
Something to keep in mind that Map, Set, etc most times already have a very distinct ordering which is depending on the concrete implementation. E.g. if we have a HashMap then it is always unsorted. And even if we would call the add() operations in the 'correct' order then it will still end up random in the HashMap. Same applies to TreeMap which is always sorted after the key.
So it might _only_ have an impact on the writer side anyway, isn't?
And there it might cause a useless performance impact in case we don't need the sorting.
Because the default ordering in JSON-B is Lexigraphical, isn't?
So that would mean that we would not be able to just write out the Map but first would need to sort the keys and then write out the values in that order. Sounds a bit too much for me in most cases.
We could probably introduce another config flag to indicate default sorting of collections?
What about order applied as annotation to a Map or Set directly?
Contributor guide
Research direction
Start by reviewing the JSON-B specification’s definition of PropertyOrderStrategy and its treatment of JSON-B properties, Map, and Set values. Use issue #78 and its comment thread to determine whether the behavior needs clarification or a separate configuration option, then document the resolved scope and ordering expectations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, documentation
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100