-
-
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
SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS should not apply to Maps with uncomparable keys #4773
Comments
Yes, this is an unfortunate issue and it does feel like not-sorting non- But until there's a fix (which probably needs to go in 2.19 for being bit risky change, potentially), there's one thing you may be able to use disable sorting for such one thing:
see f.ex test "src/test/java/com/fasterxml/jackson/databind/struct/FormatFeatureOrderedMapTest.java"
it might also be possible to apply it via ConfigOverrides ( Anyway, on per-field basis this override could help. |
Add a reproducible failing test via #4776. Thank you for reproduction @nathanukey! This issue feels like general case where we make the behavior... (of simply serializing un-ordered)
WDYT, @cowtowncoder ? |
@JooHyukKim Agreed: sounds like a plan -- with a feature, with defaults like you suggested. |
Implemented in 2.19 version via #4778 , we just released 2.18.1, so not so sure about expected date. Further Actions to Take
|
Done! |
@JooHyukKim Thank you for updating docs too -- I don't always remember to do that. |
Search before asking
Describe the bug
We have a global ObjectMapper configured in springboot used to convert objects to JSON for REST return values as well as sending objects over JMS and other places.
To have somewhat deterministic ordering of the JSON elements, we have turned on
objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
This has been working fine for years, but now one of the other teams have implemented a map of exchange rates
Map<java.util.Currency, internal.dto.ExchangeRate> exchangeRates
When the system tries to convert this to JSON, it causes an exception:
The solution seems to be to disable map sorting feature, but then we lose the huge value this has given everywhere else with deterministic ordering.
In this situation, would be preferable if the fallback was just not to sort a map that can't be sorted. Perhaps warrants a different feature flag, ORDER_COMPARABLE_MAP_ENTRIES_BY_KEYS?
Some way to specify global sorting comparators would be nice, but since there is always possibility a new Map would be created using keys that weren't sorted, defaulting to converting/sending message (even if not sorted) would still be preference.
That secondary ability to sort seems to already be raised here: #2162
But still feel this is separate issue/bug, ability to keep sorting feature without failing on unsortables.
Version Information
2.14
Reproduction
Expected behavior
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: