Skip to content

Allow Optional deserialization for "absent" value as Java null (like other Reference types), not "empty" #251

Closed
@cowtowncoder

Description

@cowtowncoder

So, for case like:

public class OptionalnBean {
   Optional<String> value;

   @JsonCreator
   public OptionalnBean(@JsonProperty("value") Optional<String> value) {
     this.value = value;
   }
}

with JSON like

{ }

current handling would assign Optional.empty() to value. But other reference types, like AtomicReference will instead assign null. This is to differentiate case of reading JSON like:

{ "value" : null }

in which value for all reference types becomes "empty" value (new AtomicReference<>, Optional.empty()).

This should be fixed for 2.14. But since this is a behavioral change it is also necessary to add configurability to allow old behavior, at least for 2.x.
And to maximize backwards compatibility we probably have to default to old and (IMO) sub-optimal handling.

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