我有一个 JSON 对象,例如:
{"name":"John", "grade":"A"}
或者
{"name":"Mike", "grade":"B"}
或者
{"name":"Simon", "grade":"C"}
ETC
我正在尝试将上面的 JSON 映射到:
@JsonIgnoreProperties(ignoreUnknown = true)
public class Employee{
@JsonIgnoreProperties(ignoreUnknown = true)
public enum Grade{ A, B, C }
Grade grade;
String name;
public Grade getGrade() {
return grade;
}
public void setGrade(Grade grade) {
this.grade = grade;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
上述映射工作正常,但将来会有更多“等级”类型,比如 D、E 等,这会破坏现有映射并引发以下异常
05-08 09:56:28.130: W/System.err(21309): org.codehaus.jackson.map.JsonMappingException: Can not construct instance of Employee from String value 'D': value not one of declared Enum instance names
有没有办法忽略枚举类型中的未知字段?
谢谢