开发者

JSON Mapping Exception constructing Map Key of enum from string

开发者 https://www.devze.com 2023-04-01 16:37 出处:网络
I\'m getting a JSON Mapping exception when trying to construct a HashMap. The map is keyed on an enum

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?


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"}}}
0

精彩评论

暂无评论...
验证码 换一张
取 消