开发者

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?


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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜