Skip to content

MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUM does not work for Enum keys of Map #1988

@Myp3ik

Description

@Myp3ik

Using 2.9.5 version libraries.
Works on simple fields, but no on the keys of the map.
Example:

public class Test {
    public void test() throws IOException {
        String value = "{" +
                "  \"Works\" : 1," +
                "  \"SomeMap\" : {" +
                "    \"One\" : 1," +
                "    \"Two\" : 2 +
                "  }" +
                "}";
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
        mapper.readValue(value, A.class);
    }
}

class A {
    @JsonProperty
    private Integer works;
    @JsonProperty
    private Map<MyEnum, Integer> someMap;
}

enum MyEnum {
    @JsonProperty("one") ONE,
    @JsonProperty("two") TWO
}

Two fields are successfully deserialized: "works" and "someMap", but insides of a map are not.

com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize Map key of type com.test.MyEnum from String "One": not a valid representation, problem: (com.fasterxml.jackson.databind.exc.InvalidFormatException) Cannot deserialize Map key of type com.test.MyEnum from String "One": not one of values excepted for Enum class: [one, two]
at [Source: (String)"{ "Works" : "", "SomeMap" : { "One" : "", "Two" : "" }
}"; line: 1, column: 36]
at [Source: (String)"{ "Works" : "", "SomeMap" : { "One" : "", "Two" : "" }
}"; line: 1, column: 36] (through reference chain: com.test.A["SomeMap"])

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