-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[Jackson-3] Add new DeserializationProblemHandler.handleNullForPrimitives()
#5493
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
base: 3.0
Are you sure you want to change the base?
Conversation
DeserializationProblemHandler.handleNullForPrimitives()
DeserializationProblemHandler.handleNullForPrimitives()DeserializationProblemHandler.handleNullForPrimitives()
src/main/java/tools/jackson/databind/DeserializationContext.java
Outdated
Show resolved
Hide resolved
src/main/java/tools/jackson/databind/DeserializationContext.java
Outdated
Show resolved
Hide resolved
|
Thank you @pjfanning ! |
|
API change, needs to go in 3.x (for 3.1.0), not patch. |
src/main/java/tools/jackson/databind/deser/DeserializationProblemHandler.java
Show resolved
Hide resolved
| if (_isCompatible(targetClass, instance)) { | ||
| return instance; | ||
| } | ||
| return reportInputMismatch(deser, msg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is problem with handler providing incompatible value, needs to use specific failure message and NOT generic "no nulls for primitives".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified exception thrown AND added test about this case also
| } | ||
| // In case our problem handler providing incompatible value, | ||
| throw new InvalidFormatException(_parser, | ||
| String.format("Cannot deserialize value of type %s from type %s", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is better, but might be confusing as it does not identify handler as the source of failure: caller might assume core Jackson is doing something funny. So should indicate it is a registered DeserializationProblemHandler that provided bad value.
I think some existing handler processing methods show examples.
| throw new InvalidFormatException(_parser, | ||
| String.format("Cannot deserialize value of type %s from type %s", | ||
| targetClass, ClassUtil.getClassDescription(instance)), | ||
| instance, targetClass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of plain targetClass, use method from ClassUtil, I think nameOf(Class<?>).
Handles nulls and surrounds with backtick (plus I think deals with array class types).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting very close to good! Just added a couple of notes.
And also: needs to target 3.x, not 3.0, as per my earlier comment.
fix #5469
Target branch TBD