`MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUM` does not work for `Enum` keys of `Map`
See original GitHub issueUsing 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 typecom.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”])
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (6 by maintainers)
Ok. So basically case-insensitivity does not work for Map keys that are
Enum
s.Verified that the last test passes with Jackson 2.13.0, assuming
MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS
is enabled. Fix itself may have been done for 2.12.x if anyone wants to check it out, but I’ll mark fixed-as 2.13.0 since that is what I verified.