Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
unintended opened this issue Jun 7, 2021 · 1 comment
Milestone

Comments

@unintended
Copy link

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.

@cowtowncoder
Copy link
Member

Interesting! Thank you for reporting this, it does sounds like a bug for an edge case, caused by new coercion configuration settings in 2.12.

@cowtowncoder cowtowncoder added 2.12 and removed 2.13 labels Jun 7, 2021
cowtowncoder added a commit that referenced this issue Jun 8, 2021
@cowtowncoder cowtowncoder added this to the 2.12.4 milestone Jun 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants