-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
MapSerializer._orderEntries should check for null keys. #1411
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
Comments
This is about jackson-databind 2.8.3. |
Interesting... thank you for reporting this, will do. |
@cowtowncoder First of all, you aren't returning the Secondly, the value stored for I've given this some more thoughts and I now think that the right way of fixing this issue would look like this: protected Map<?,?> _orderEntries(Map<?,?> input)
{
// minor optimization: may already be sorted?
if (input instanceof SortedMap<?,?>) {
return input;
}
try {
return new TreeMap<Object,Object>(input);
} catch (Throwable ignored) {
return input
}
} This would also cover the case were keys aren't Catching I'm usually not a fan of using exceptions for logic but think this is an exception to the rule since it would impose zero performance overhead in the "good" case while still returning correct, albeit unsorted, values in the "bad" case. Sorry I didn't catch the problem before the 2.8.4 release. :( |
I disagree in sending unordered entries, however, so I don't want to do that. I am bit ambivalent on best way to proceed here; perhaps throwing exception is better then. I can do that, but give proper explanation. The thing is this: JSON does not allow |
Uh, sorry. I wasn't aware that An Enabling or disabling We are talking about new behavior here: I'd suggest that you document over at My rationale for this is that I'm just trying to be helpful here, throwing my brain and 2 cents into your brainstorming pool, but you are way deeper involved in the topic than I am so I'm not sure about the actual value of my rambling. This isn't meant as a "I am right and you are wrong!" argument at all. I also feel sorry about the whole issue since I was the one who originally suggested |
Actually there is per-property override also using
I think I do have an idea of what to do with null entry... I'll have to double-check to see how I do agree in that quietly dropping an entry is not desirable. |
should be changed to
TreeMap
will otherwise throw aNullPointerException
.This would mean that a
Map
is potentially serialized unsorted as a fallback even ifORDER_MAP_ENTRIES_BY_KEYS
is active but I guess that's still better than exploding with an exception.The text was updated successfully, but these errors were encountered: