Skip to content

READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE doesn't work with empty strings ("")Β #3171

@unintended

Description

@unintended

version: 2.12.13

public enum PetType {
  @JsonEnumDefaultValue
  cat,
  dog
}

public class Pet {
  private PetType type;
}

deserializing of {type: "fish"} results in type == PetType.cat
but deserializing of {type: ""} results in coercion failure:

com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot coerce empty String ("") to PetType value (but could if coercion was enabled using CoercionConfig)

Looks like CoercionConfigs takes precedence before READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE. Enabling ACCEPT_EMPTY_STRING_AS_NULL_OBJECT makes all "" enums nulls.

Expected behavior: empty strings are mapped to default enum value if READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE is enabled and ACCEPT_EMPTY_STRING_AS_NULL_OBJECT is not enabled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions