bolerio / mjson

Lean JSON Library for Java, with a compact, elegant API.
Apache License 2.0
83 stars 24 forks source link

Update Object to use LinkedHashMap rather than HashMap #35

Closed arkban closed 1 month ago

arkban commented 4 years ago

Updated HashMap usages to use LinkedHashMap to preserve order of key insertion in Objects.

AFAIK this is not part of the spec yet makes the behavior consistent with other JSON parsers: 1 2 3 4

bolerio commented 1 month ago

Apologies for the years long reaction to this. The project was in a bit of hiatus. Thanks for the PR, but important is this ordering? There is no expectation in JSON spec to have properties be ordered. LinkedHashMap has an obvious overhead, both in terms of memory and time for maintaining the linkage.

I will reject the PR because it is possible to customize the library and get this behavior without changing the main codebase. You can extend Json.Factory to provide your own JSON object implementation and then plug in through the Json.setGlobaFactory method.