question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUM` does not work for `Enum` keys of `Map`

See original GitHub issue

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”])

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
cowtowncodercommented, Apr 4, 2018

Ok. So basically case-insensitivity does not work for Map keys that are Enums.

0reactions
cowtowncodercommented, Oct 13, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jackson databind enum case insensitive - java - Stack Overflow
it uses HashMap to hold enum values and HashMap doesn't support case insensitive keys. in answers above, all chars should be uppercase or ......
Read more >
A Guide to EnumMap - Baeldung
EnumMap is a Map implementation that exclusively takes Enum as its keys. In this tutorial, we'll discuss its properties, common use cases ...
Read more >
Enum — Elixir v1.13.4 - HexDocs
Returns a list where each element is the result of invoking fun on each corresponding element of enumerable . For maps, the function...
Read more >
Java EnumMap - Medium
EnumMap is one of the specialized implementation of Map interface for use with enum type keys, introduced in Java 1.5 with enumeration type....
Read more >
Difference Between EnumMap and HashMap - GeeksforGeeks
EnumMap and HashMap both are the classes that implement the Map ... EnumMap doesn't allow inserting null key if we try to insert...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found