{"record":{"id":"d7ace2d683e04328","repo":"FasterXML/jackson-databind","slug":"type-enumtype-not-java-enum-type","errorCode":null,"errorMessage":"Type ${enumType} not Java Enum type","messagePattern":"Type (.+?) not Java Enum type","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/tools/jackson/databind/deser/jdk/EnumSetDeserializer.java","lineNumber":66,"sourceCode":"     * to indicate whether single value may be taken to mean an unwrapped one-element array\n     * or not. If null, left to global defaults.\n     */\n    protected final Boolean _unwrapSingle;\n\n    /*\n    /**********************************************************************\n    /* Life-cycle\n    /**********************************************************************\n     */\n\n    @SuppressWarnings(\"unchecked\")\n    public EnumSetDeserializer(JavaType enumType, ValueDeserializer<?> deser)\n    {\n        super(EnumSet.class);\n        _enumType = enumType;\n        // sanity check\n        if (!enumType.isEnumType()) {\n            throw new IllegalArgumentException(\"Type \"+enumType+\" not Java Enum type\");\n        }\n        _enumDeserializer = (ValueDeserializer<Enum<?>>) deser;\n        _unwrapSingle = null;\n        _nullProvider = null;\n        _skipNullValues = false;\n    }\n\n    @SuppressWarnings(\"unchecked\" )\n    protected EnumSetDeserializer(EnumSetDeserializer base,\n            ValueDeserializer<?> deser,\n            NullValueProvider nuller, Boolean unwrapSingle) {\n        super(base);\n        _enumType = base._enumType;\n        _enumDeserializer = (ValueDeserializer<Enum<?>>) deser;\n        _nullProvider = nuller;\n        _skipNullValues = NullsConstantProvider.isSkipper(nuller);\n        _unwrapSingle = unwrapSingle;\n    }","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/FasterXML/jackson-databind/blob/87876ca5c0569b4933aec2d30d6225e4b9ba3a43/src/main/java/tools/jackson/databind/deser/jdk/EnumSetDeserializer.java#L48-L84","documentation":"EnumSetDeserializer's constructor enforces that the JavaType passed in is a real Java enum type (enumType.isEnumType()). If a non-enum type is supplied the deserializer cannot be built, because EnumSet requires an Enum element type at the JVM level. This is an internal invariant guard thrown as IllegalArgumentException during deserializer construction.","triggerScenarios":"Constructing EnumSetDeserializer manually with a JavaType that is not an enum; using @JsonDeserialize on an EnumSet field whose generic argument resolves to a non-enum class; a TypeFactory/TypeBinding misconfiguration that erases or replaces the enum element type before the deserializer is built.","commonSituations":"Refactoring an enum into a regular class and forgetting to update an EnumSet-typed field; mixed type bindings with custom modules that swap the element type; generic type erasure in a wrapper that passes raw or wildcard types into an EnumSet context.","solutions":["Verify the element type of the EnumSet is declared as a concrete enum, e.g. EnumSet<MyEnum>, and not EnumSet<?> or EnumSet<Object>.","If you build the deserializer by hand, resolve the enum class via TypeFactory and pass JavaType.isEnumType()==true.","Switch the field type from EnumSet to Set<YourType> when the element type is not guaranteed to be an enum.","Audit custom Deserializers / SimpleModule registrations that might replace EnumSet handling with a wrong type."],"exampleFix":"// before\npublic class Holder { public EnumSet<?> items; } // raw element type\n\n// after\npublic enum Color { RED, GREEN }\npublic class Holder { public EnumSet<Color> items; }","handlingStrategy":"validation","validationCode":"JavaType t = mapper.constructType(elementClass);\nif (!t.isEnumType()) {\n    throw new IllegalStateException(\"Refusing to build EnumSet deserializer for non-enum \" + t);\n}","typeGuard":"boolean isEnumSetElementType(Class<?> cls) {\n    return cls != null && cls.isEnum();\n}","tryCatchPattern":null,"preventionTips":["Always declare EnumSet fields with a concrete enum generic (EnumSet<MyEnum>, never EnumSet<?>).","When registering custom deserializers, branch on type.isEnumType() before touching EnumSetDeserializer.","Unit-test deserialization of every EnumSet field after enum refactors."],"tags":["deserialization","enum","enumset","type-resolution","illegal-argument"],"backgroundTag":null,"analyzedSha":"87876ca5c0569b4933aec2d30d6225e4b9ba3a43","analyzedAt":"2026-08-11T12:55:24.033Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}