Skip to content

Enum deserialization does not respect JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_VALUES override #5814

Description

@eatdrinksleepcode

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_VALUES is documented as working for enums ("allows case-insensitive matching of (some) property values, such as Enums"), but it actually has no effect on enum deserialization.

When constructing EnumDeserializer, BaseDeserializerFactory only checks MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS when passing the caseInsensitive parameter.

Also, when searching for occurrences of ACCEPT_CASE_INSENSITIVE_VALUES across all of FasterXML, there are only 17 occurrences. It is straightforward to verify that none of these occurrences affect enum deserialization.

As far as I can tell this has always been true since 2.10 when ACCEPT_CASE_INSENSITIVE_VALUES was introduced, even though it was documented from the start to work with enums.

Version Information

2.21.2, 3.1.0

Reproduction

import com.fasterxml.jackson.annotation.*;
import tools.jackson.databind.ObjectMapper;

enum Status {
    SENT,
    @JsonEnumDefaultValue UNKNOWN
}

class Response {
    @JsonFormat(with = {
            JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_VALUES,
            JsonFormat.Feature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE
    })
    public Status status;
}

public class Test {
    public static void main(String[] args) {
        String json = "{\"status\":\"sent\"}";
        Response response = new ObjectMapper().readValue(json, Response.class);

        System.out.println(response.status); // Expected: SENT, Actual: UNKNOWN
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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