Closed
Description
Describe the bug
A NullPointerException occurs parsing a (YAML) file to a Kotlin class. The object is created using a @JsonCreator that does not use all properties in the file.
Version information
2.15.0
To Reproduce
Have a data class SomeTaskListClass
with a property that is a list of another class Task
. The Task
class has a @JsonCreator
annotated static method to create it. It does not need/mention all properties of the file. The parser is configured to ignore those fields.
Parsing results in this error
com.fasterxml.jackson.databind.JsonMappingException: Cannot invoke "com.fasterxml.jackson.core.JsonParser.streamReadConstraints()" because "p" is null (through reference chain: SomeTaskListClass["tasks"]->java.util.ArrayList[0])
(...)
Caused by: java.lang.NullPointerException: Cannot invoke "com.fasterxml.jackson.core.JsonParser.streamReadConstraints()" because "p" is null
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handlePolymorphic(BeanDeserializerBase.java:1749)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:541)
The line casing the error in handlePolymorphic
is
JsonParser p2 = unknownTokens.asParser(p.streamReadConstraints());
a few lines later is a null check for p
.
Looking at the call-site in _deserializeUsingPropertyBased
, that NPE makes sense
return handlePolymorphic(null, ctxt, bean, unknown); // <-- passing null for `p`
Expected behavior
Parsing works without error.