-
-
Notifications
You must be signed in to change notification settings - Fork 177
The ObjectMapper.readValue extension methods need the type param to be bound to Any #480
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
I think this is the same as #399. Adding that |
I'm working on the PR today. One question is what exception should be thrown for the non-nullable versions when they deserialize a null? |
Hmm, I'm not sure what is thrown when the existing |
Okay. I'll look into what strictNullChecks throws. I was originally going to just throw a new DatabindException, but I wasn't sure how to implement it.
Similarly, I didn't know how to throw a JsonMappingException because all of the non-deprecated ctors take a Closeable processor argument, which I won't have from just wrapping the readValue calls and checking for null. |
Hmm, that's a new exception in 2.13, so I'm not sure—it looks like perhaps implementations are supposed to add the information passed to those functions to the exception message? The only usage in jackson-databind accumulates into a All that is to say, it looks like extending |
+1 for what @dinomite said. One other quick note:
So code in 2.x differs from 3.0 (master) here, unfortunately. The intent is, however, that the vast majority of code should not directly instantiate exceptions but either:
which will properly attach necessary information, as well as have same (or, sometimes, similar) signature between 2.x and 3.x code bases. I know this is a bit of hassle due to rather long development cycle for 3.0 (unintentional. due to 2.x lifetime exceeding initial expectations). |
@dinomite Hi, I don't think adding a new extension method is the right approach, we should make the existing extension method work
|
This issue is closed as a duplicate of #399. |
Describe the bug
One can violate the type system by deserializing null where it was not intended
To Reproduce
Expected behavior
Deserialization should fail when the declared type parameter is not explicitly nullable
Versions
Kotlin: 1.4
Jackson-module-kotlin: 2.13
Jackson-databind: 2.13
Additional context
The fix is to add a type bound to the current methods and to add a new set of nullable methods:
The text was updated successfully, but these errors were encountered: