-
-
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
MapDeserializer
can not merge Map
s with polymorphic values
#2336
Comments
Thank you for reporting this. I hope to look into this in near future, but there's bit of backlog of items so apologies in advance for this probably taking a while. One note on abstract type deserializer: that may be ok as such deserializer should be passed a |
Thank you for a quick reply. I started looking at this in the case of a polymorphic type not in a map and found this in the code (which I think was your comment): // 20-Oct-2016, tatu: Also tricky -- for now, report an error
if (_valueTypeDeserializer != null) {
ctxt.reportBadDefinition(getType(),
String.format("Cannot merge polymorphic property '%s'",
getName()));
// return _valueDeserializer.deserializeWithType(p, ctxt, _valueTypeDeserializer);
} So I am guessing there is something more structurally difficult about doing this in general with the way the deserializers are currently written? |
Ok, finally found time to revisit this. So, yes, merging polymorphic values is tricky because extra polymorphic type information must be handled, and it is not clear how you would merge, say, instances of different types (new type might have properties that old instance does not have). Now: for containers it probably would make most sense to either:
Of these, I don't think (1) can made to work. (2) might be possible, and I think I'll try that next. |
Ok things look promising: test had one problem (should not have |
MapDeserializer
can not merge Map
s with polymorphic values
So, with 2.10 things will now work (assuming If attempts to provide some form of risky merging for polymorphic values are still desired, a new issue should be created (with reference to this issue for back story). But I hope this improvement is still useful for at least some cases. |
I have found what appears to be a defect in
MapDeserializer
when trying to use JSON merging, with a Map where the values are polymorphic types. So for example, consider aMap<String, FooBase>
whereFooBase
is an abstract class (annotated withJsonTypoInfo
andJsonSubTypes
etc). When trying to merge another structure into that map, it fails when trying to merge an existing value - i.e. where there is an existing mapping from key "SomeKey" to a concrete subclass ofFooBase
, it fails with exception:Having looked at the code I believe the issue is in
MapDeserializer
, specifically in method_readAndUpdateStringKeyMap
here:Note in the above code, if there is an existing value it calls deserialize on the
valueDes
instance which is just an abstract deserializer rather than leveraging the type (intypeDeser
). I don't know much more than that yet so I was hoping that someone could offer some guidance about whether this is easily fixed or going to be more involved. I'd be happy to work on a pull request with some guidance from people more familiar with the codebase.Here is a fully self-contained example that illustrates the issue:
The text was updated successfully, but these errors were encountered: