3
votes

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 ?

1

1 Answers

0
votes

This has been fixed by a change to the Jackson library itself, as of https://github.com/FasterXML/jackson-databind/pull/1642/files

According to https://github.com/FasterXML/jackson-databind/pull/1642 it has been backported to Jackson 2.8.9, so try upgrading to that.