FasterXML/jackson-databind · error · IllegalArgumentException

Type {} not Java Enum type

Error message

Type {} not Java Enum type

What it means

Thrown by the EnumSetDeserializer constructor (sanity check) when the JavaType passed for the enum set's element type is not actually a Java enum type. The constructor calls enumType.isEnumType() and rejects non-enum types. This is a configuration/type-resolution error indicating that an EnumSet deserializer was constructed for a non-enum element type.

Source

Thrown at src/main/java/tools/jackson/databind/deser/jdk/EnumSetDeserializer.java:66

     * to indicate whether single value may be taken to mean an unwrapped one-element array
     * or not. If null, left to global defaults.
     */
    protected final Boolean _unwrapSingle;

    /*
    /**********************************************************************
    /* Life-cycle
    /**********************************************************************
     */

    @SuppressWarnings("unchecked")
    public EnumSetDeserializer(JavaType enumType, ValueDeserializer<?> deser)
    {
        super(EnumSet.class);
        _enumType = enumType;
        // sanity check
        if (!enumType.isEnumType()) {
            throw new IllegalArgumentException("Type "+enumType+" not Java Enum type");
        }
        _enumDeserializer = (ValueDeserializer<Enum<?>>) deser;
        _unwrapSingle = null;
        _nullProvider = null;
        _skipNullValues = false;
    }

    @SuppressWarnings("unchecked" )
    protected EnumSetDeserializer(EnumSetDeserializer base,
            ValueDeserializer<?> deser,
            NullValueProvider nuller, Boolean unwrapSingle) {
        super(base);
        _enumType = base._enumType;
        _enumDeserializer = (ValueDeserializer<Enum<?>>) deser;
        _nullProvider = nuller;
        _skipNullValues = NullsConstantProvider.isSkipper(nuller);
        _unwrapSingle = unwrapSingle;
    }

View on GitHub (pinned to a50c7d2a1d)

Solutions

  1. Ensure the JavaType passed to EnumSetDeserializer has a concrete enum raw class (e.g., MyEnum.class, not Object.class or Enum.class).
  2. If declaring EnumSet fields, always parameterize them: EnumSet<MyEnum> not raw EnumSet.
  3. In custom factories, check enumType.isEnumType() before constructing the deserializer.
  4. Use TypeFactory to construct the correct parameterized type if resolving from reflection metadata.

Example fix

// before: raw EnumSet, type erasure yields non-enum element type
private EnumSet myEnumSet;
// after: properly parameterized
private EnumSet<MyEnum> myEnumSet;
Defensive patterns

Strategy: type-guard

Validate before calling

// Ensure the JavaType is an enum before constructing EnumSetDeserializer
if (enumType.isEnumType()) {
    new EnumSetDeserializer(enumType, deser);
} else {
    throw new IllegalArgumentException("Not an enum: " + enumType);
}

Type guard

static boolean isEnumElementType(JavaType type) {
    return type.isEnumType() && type.getRawClass().isEnum();
}

Prevention

When it happens

Trigger: Constructing an EnumSetDeserializer directly with a JavaType whose raw class is not an enum. A custom module or deserializer factory that routes a non-enum type to EnumSetDeserializer. A type resolution bug where the element type of an EnumSet resolves to a raw or erased type.

Common situations: Custom module code that manually creates EnumSetDeserializer instances. Erasure issues with generic EnumSet fields where the element type is not properly resolved. Type erasure on a field declared as EnumSet (raw) without a type parameter.

Related errors


AI-assisted analysis of FasterXML/jackson-databind@a50c7d2a1d (2026-08-06). Data as JSON: /api/errors/423037d6325d61b5. Report an issue: GitHub.