Open luozhenyu opened 1 year ago
In theory we could consider adding new version of handleMissingInstantiator()
which takes JavaType
(to retain generic type info). That seems like the way it could be done.
But that is called by handleMissingInstantiator()
from DeserializationContext
which would need to have overrides and delegation from old method as well, for backwards compatibility.
Although TBH, this module also uses a bit hacky way to go about construction as well. So maybe there could be different way that would not rely on having to find deserializer.
Not sure if AnnotatedWithParams
route would be feasible; I guess one wouldn't need to get full deserializer if we could get ValueInstantiator
to work.
Code
The following code throws java.lang.ClassCastException. The type of
response.getPayload()
is notUser
butLinkedHashMap
Cause
@cowtowncoder It seems the JsonDeserializer is fetched by
Class<?> instClass
rather than a ParameterizedType.https://github.com/FasterXML/jackson-modules-base/blob/2.15/no-ctor-deser/src/main/java/com/fasterxml/jackson/module/noctordeser/MissingInstantiatorHandler.java#L34-L37
Solution
The overrided method
DeserializationProblemHandler#handleMissingInstantiator(DeserializationContext ctxt, Class<?> instClass, ValueInstantiator valueInst, JsonParser jsonParser, String msg)
does not suppy generic information. Maybe we can extend class AnnotatedWithParams and override itspublic abstract Object call() throws Exception;
. Then we set it to the StdValueInstantiator's _defaultCreator field?