【发布时间】:2012-09-10 05:31:44
【问题描述】:
我正在使用 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;
}
}
我添加了一个@JsonValue,这似乎完成了将对象序列化为的工作:
{"event":"forgot password"}
但是当我尝试反序列化时,我得到了一个
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
我在这里错过了什么?
【问题讨论】:
-
你试过
{"Event":"FORGOT_PASSWORD"}吗?请注意 Event 和 FORGOT_PASSWORD 的上限。 -
谁来这里也检查 getter setter 语法如果你遵循不同的命名约定,即而不是
getValue这个GetValue不起作用
标签: java enums jackson jsonserializer