小编poo*_*man的帖子

Jackson enum Serializing和DeSerializer

我正在使用JAVA 1.6和Jackson 1.9.9我有一个枚举

public enum Event {
    FORGOT_PASSWORD("forgot password");

    private final String value;

    private Event(final String description) {
        this.value = description;
    }

    @JsonValue
    final String value() {
        return this.value;
    }
}
Run Code Online (Sandbox Code Playgroud)

我添加了一个@JsonValue,这似乎完成了将对象序列化为:

{"event":"forgot password"}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试反序列化时,我得到了一个

Caused by: org.codehaus.jackson.map.JsonMappingException: Can not construct instance of com.globalrelay.gas.appsjson.authportal.Event from String value 'forgot password': value not one of declared Enum instance names
Run Code Online (Sandbox Code Playgroud)

我在这里错过了什么?

java enums jsonserializer jackson

208
推荐指数
11
解决办法
22万
查看次数

标签 统计

enums ×1

jackson ×1

java ×1

jsonserializer ×1