-
Notifications
You must be signed in to change notification settings - Fork 53
ImmutableSetMultimap deserialization, or completing the TODOs #67
Comments
Yes, in general, pull requests are good. If patch is single-file, couple of lines changed, including in issue is even simpler. For this particular one, I'll see if I can figure out a simple way to directly support it. One question I have is with semantics: does |
Hmmh ok. So the problem is that due to immutability, a builder must be used. That is not problematic per se, but Guava does not use much of OO with builders, so generic construction is difficult: that is, sharing of implementations that use builders (which for Maps are really very similar, API-wise) is difficult if not impossible. This means that quite a bit of almost identical code needs to be duplicated. So, this is definitely doable, but it does not seem to me like a one-liner. Patches are welcome! |
They could have done a better job of putting it all in one place, but yes they do specify traversal order. The user can specify the order with comparators (one for keys, one for values) or else the multimap will preserve the order the keys and values were inserted. The latter behavior (traversal order == insertion order) is the one I'm referring to in this issue. Here's a few snippets from Guava's latest on Github. Let me know if it's not convincing. In that case I'll probably file a bug with Guava. I know they're trying to make this clear... From keySet():
From values():
Not necessarily. Not if you're ok with the lazy solution! :) This module already supports some Immutable__ types without builders by building a mutable instance, then calling Line 58 in 0b3cbb7
The issue is right here: jackson-datatype-guava/src/main/java/com/fasterxml/jackson/datatype/guava/GuavaDeserializers.java Lines 199 to 216 in 151b01c
It does not have special handling for
The lazy solution would be to replace this:
with this:
That should work because
Would you be ok with that lazy solution for now? |
Very good information, thank you. Yes, I think the lazy solution is fine: I'd rather have things working correctly first, and only then worry about optimality. :) It might be best if you did do a PR I think, since I think you know better than I do what exactly to test (and obviously ensure it works for your use case). |
Fix for issue #67 - ImmutableSetMultimap ordering
I just tried serializing a
I was under the impression that this issue was meant to fix serialization as well. Should I file a separate bug report? |
@cowwoc I think the report was specifically about deserialization, but title did not reflect that. I updated the title as the first step. Obviously serialization should also work, did not realize it does not. |
There are a few TODOs in the source code of
GuavaDeserializers
. For example:jackson-datatype-guava/src/main/java/com/fasterxml/jackson/datatype/guava/GuavaDeserializers.java
Line 200 in 151b01c
The
ImmutableSetMultimap
one matters to me because the default deserializer does not have the same semantics for traversal order of entries. The order of the entries in the source is important, but it is lost in deserialization when it is put into aHashMultimap
.I imagine it could be a one line fix, by defaulting to
LinkedHashMultimap
instead. But I bet that's not what the person who wrote that TODO had in mind.In general, for TODOs like this one, do you want pull requests?
The text was updated successfully, but these errors were encountered: