Skip to content

Allow @JsonCreator annotated Creator to return null #4938

@f-aubert

Description

@f-aubert

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

When using JsonCreator on a factory (static) method, we have the possibility of returning null (because for example all the arguments are empty). However during deserialization an exception is thrown, java.lang.NullPointerException: JSON Creator returned nul.

I think it would make sense to allow deserialization to null

Describe the solution you'd like

Improve the code robustness in the BeanEntityDeserializer to allow Deserialization to null if a static JsonCreator explicitly allows it.

Usage example

@JsonCreator
public static Localized3 of(@JsonProperty("en") String en, @JsonProperty("de") String de, @JsonProperty("fr") String fr) {
        if (en == null && de == null && fr == null) {
            return null;
        }

        return new Localized3(en, de, fr);
}

should be allowed for Deserialization and { en: null, de: null, fr: null } should deserialize to null

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    2.19Issues planned at 2.19 or later

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions