Skip to content

Use @JsonSetter(nulls=...) to specify handling of null values during deserialization #1402

@cowtowncoder

Description

@cowtowncoder

(note: replaces #1269, earlier #988 and #830)

It looks like there is strong desire to define alternate methods for handling incoming null values; instead of just assigning as Java nulls to:

  1. Ignore value (avoid calling setter)
  2. Fail (throw exception)
  3. Convert to a default value

Since applicability is probably not universal for all cases (that is, different types could well follow different rules), it seems that approach similar to @JsonInclude would work.
However, I don't think use of @JsonInclude itself works here, as its settings are partially output-specific; so ideas are reusable, implementation not.

Instead, I think use of existing @JsonSetter by adding:

  • Nulls value enumeration for a small set of standard behaviors (and perhaps, in future, for custom handler?)
  • nulls property for dealing with value itself (POJO, Collection, wrapper type)
  • contentNulls for contents of structured types: array/collection elements, Map values, POJO properties

Changes to annotation are simple; changes to deserializers would be sizable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    most-wantedTag to indicate that there is heavy user +1'ing action

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions