Skip to content

Conversation

@JooHyukKim
Copy link
Member

@JooHyukKim JooHyukKim commented Dec 10, 2025

fix #5469

Target branch TBD

@JooHyukKim JooHyukKim changed the base branch from 3.x to 3.0 December 10, 2025 15:17
@JooHyukKim JooHyukKim changed the title fix #5469 Add new DeserializationProblemHandler.handleNullForPrimitives() Dec 10, 2025
@JooHyukKim JooHyukKim changed the title Add new DeserializationProblemHandler.handleNullForPrimitives() [Jackson-3] Add new DeserializationProblemHandler.handleNullForPrimitives() Dec 10, 2025
@JooHyukKim
Copy link
Member Author

Thank you @pjfanning !

@cowtowncoder
Copy link
Member

API change, needs to go in 3.x (for 3.1.0), not patch.

if (_isCompatible(targetClass, instance)) {
return instance;
}
return reportInputMismatch(deser, msg);
Copy link
Member

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".

Copy link
Member Author

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",
Copy link
Member

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
Copy link
Member

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).

Copy link
Member

@cowtowncoder cowtowncoder left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants