You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the type info field is missing from the json, the DeserializationContext's JsonParser's token is END_OBJECT (presumably because it nextToken'd through the object to find type and whiffed).
This makes the module fail since the JsonParser in the Module is wrong, i.e. not the same as the JsonParser in the MapDeserializer.
cowtowncoder
changed the title
When json type info is missing from json, Modules for Enums as keys of Maps always have END_TOKEN in the JsonParser
Failure with custom Enum key deserializer, polymorphic types
Nov 3, 2016
Wow. Not sure why I implemented delegating key deserializer that way; it's wrong -- should not delegate original parser in general, and in this case parser would be wrong due to buffering needed for type id.
Anyway: better way is to construct bogus TokenBuffer as JsonParser and add key (that has already been accessed and is passed as the argument), give that parser; it's safer and necessary here.
Thank you for reporting this, providing test case! Fixed for 2.8.5, to be released relatively soon (within next week or two).
Normally the
JsonParser
and theDeserializationContext
is passed to aModule
'sJsonDeserializer
.However, in the
MapDeserializer
, when deserializing aMap
with anEnum
key, theKeyDeserializer
doesn't accept theJsonParser
as an argument:https://github.com/FasterXML/jackson-databind/blob/master/src/main/java/com/fasterxml/jackson/databind/deser/std/MapDeserializer.java#L453
Object key = keyDes.deserializeKey(keyStr, ctxt);
and the
StdKeyDeserializer.DelegatingKD
uses the context's parserhttps://github.com/FasterXML/jackson-databind/blob/master/src/main/java/com/fasterxml/jackson/databind/deser/std/StdKeyDeserializer.java#L315
Object result = _delegate.deserialize(ctxt.getParser(), ctxt);
When the type info field is missing from the json, the
DeserializationContext
'sJsonParser
's token isEND_OBJECT
(presumably because itnextToken
'd through the object to find type and whiffed).This makes the module fail since the
JsonParser
in theModule
is wrong, i.e. not the same as theJsonParser
in theMapDeserializer
.Class:
Enum:
Test:
The text was updated successfully, but these errors were encountered: