jd_sharp
jd_sharp

Reputation: 53

JSON Mapping Exception constructing Map Key of enum from string

I'm getting a JSON Mapping exception when trying to construct a HashMap. The map is keyed on an enum

The input looks like this:

{"someObject":{"myMap":{"1":"2"}}}

Problem is it treats the "1" as a String and complains that it's not a valid representation as it's not one of the values of the enum.

Any idea how to fix this?

Upvotes: 1

Views: 1266

Answers (1)

nicholas.hauschild
nicholas.hauschild

Reputation: 42834

Have you tried using the actual names of the enum values instead of their ordinal values?

enum Direction {
    NORTH,SOUTH,EAST,WEST;
}

and

{"someObject":{"myMap":{"NORTH":"2"}}}

Upvotes: 1

Related Questions