An Enum Class, ColorName is generated using jsonschema2pojo from ColorName json file.So by default the Enum class has by default fromValue method annotated with @JsonCreator.
@JsonCreator
public static ColorName fromValue(String value) {
ColorName constant = constants.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
} else {
return constant;
}
}
If this class is used to deserialize the json string to Java object and if there is a new/wrong Enum value passed in the json, then the deserialization fails with IllegalArgumentException()
When attempted to avoid this error using below, it didn't work
ObjectMapper om = new ObjectMapper(); om.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
The issue seems to be because @JsonCreator is honoured always. Is there a way to indicate the deserializer to skip this or ignore unknown enum value ?