Skip to content

Blank strings should not be deserialized as JsonNullable.undefined() #125

Open

Description

@krangerich

Context: When a request object has a field like Integer, but an empty/blank string is given, then Jackson deserializes this value as null.
When deserializing the empty/blank string into something like Optional<Integer>, then this will result in a value of Optional.empty(), not null.

The behavior of JsonNullable is inconsistent here: When using JsonNullable<Integer>, an empty/blank string will be deserialized as JsonNullable.undefined() (=not provided in the request) instead of JsonNullable.of(null) (=provided, but a null value).

I think, the best behavior here should be, that empty/blank strings should be deserialized as JsonNullable.of(null), not JsonNullable.undefined()

Activity

  1. Thorsrud22 commented on Sep 23, 2026

    @Thorsrud22
    Contributor

    Status update: #186 (carrying #126) adds an opt-in option for this and is merged for 0.2.12:

    mapper.registerModule(new JsonNullableModule().mapBlankStringToNull(true));

    With it, a blank string for a non-String target becomes JsonNullable.of(null) instead of undefined(). The default is unchanged on 0.2.x. Making it the default is kept as a possible change for a later major line (see the discussion on #152), so leaving this open for that.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions