-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
DeserializationContext.readTreeAsValue()
handles null nodes differently from ObjectMapper.treeToValue()
#4934
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
Comments
Ok, I'll need to think of how to write a test case. I think you are right since although this:
at first looks correct, I forgot that But getting access to a |
@FWest98 Yeah would be helpful if we ca get the actual working reproduction. |
It seems like the // [databind#4934]
@Test
public void testTreeAsValueFromNulls() throws Exception
{
final JsonNodeFactory nodeF = MAPPER.getNodeFactory();
try (JsonParser p = MAPPER.createParser("abc")) {
DeserializationContext ctxt = MAPPER.readerFor(String.class).createDeserializationContext(p);
assertNull(MAPPER.treeToValue(nodeF.nullNode(), Bean.class)); // works
assertNull(ctxt.readTreeAsValue(nodeF.nullNode(), Bean.class)); // fails, throws exception
}
} |
Interesting. Thank you @FWest98. |
I can reproduce the issue and know what is needed. But fix is likely bit riskier than what should go in a patch so will target 2.19, instead of 2.18 like I initially planned. |
@FWest98 Ok, fixed for 2.19 for eventual 2.19.0. Thank you for reporting this issue! |
Search before asking
Describe the bug
The
ObjectMapper
functions handle the case where the root node is the null node by specifically callinggetNullValue
of the root deserializer. The equivalentDeserializationContext
functions do not. I would expect the two functions to behave similarly, or the differences should be documented.See below for a reproducer and use case.
Version Information
2.18.1
Reproduction
My use case is that I have a custom deserializer that reads the
defaultValue
metadata field that is populated by theJsonProperty
annotation. I implement a customgetAbsentValue
function that will handle the default values. However, I also want to allow"null"
as a default value.The workaround is to cast the codec to an
ObjectMapper
, but that does not seem very nice and I would prefer not to do it, since there are no guarantees of the cast being allowed.The text was updated successfully, but these errors were encountered: