Skip to content

Add callback in DeserializationProblemHandler for "null for primitive" problem case #5469

@jnizet

Description

@jnizet

Is your feature request related to a problem? Please describe.

See #5451

Describe the solution you'd like

I'd like to be able to configure a JsonMapper with a DeserializationProblemHandler that would allow me to log when a null has been met where a primitive is required.
The new method of the DeserializationProblemHandler would allow me to log (either through separate arguments of the method, or with a ready to log message)

  • which type is expected (example: double)
  • at which location (example: com.foo.bar.Coordinates#latitude)

Usage example

var mapper = JsonMapper.builder().addHandler(new DeserializationProblemHandler() {
    @Override
    public void handleNullForPrimitive(String message) {
        logger.warn("This problem should be handled before turning FAIL_ON_NULL_FOR_PRIMITIVES: " + message);                
    }
}).build();

And if a null is found for a primitive, that would thus log something like

This problem should be handled before turning FAIL_ON_NULL_FOR_PRIMITIVES: Met null for primitive of type `int` in com.foo.bar.Coordinates#latitude

The logger could create a log an exception to have the stack trace allowing to have more context (i.e. where the deserialization happened).

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions