一个 Enum 类,ColorName 是使用 ColorName json 文件中的 jsonschema2pojo 生成的。因此,默认情况下,Enum 类具有使用 @JsonCreator 注释的 fromValue 方法。
@JsonCreator
public static ColorName fromValue(String value) {
ColorName constant = constants.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
} else {
return constant;
}
}
如果此类用于将 json 字符串反序列化为 Java 对象,并且在 json 中传递了新的/错误的 Enum 值,则反序列化失败,IllegalArgumentException()
当尝试使用以下方法避免此错误时,它不起作用
ObjectMapper om = new ObjectMapper(); om.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
这个问题似乎是因为@JsonCreator 总是很荣幸。有没有办法指示反序列化器跳过这个或忽略未知的枚举值?