{"record":{"id":"71834f94d6b5e692","repo":"FasterXML/jackson-databind","slug":"unsuitable-method-decorated-with-jsoncreator","errorCode":null,"errorMessage":"Unsuitable method ({}) decorated with @JsonCreator (for Enum type {})","messagePattern":"Unsuitable method \\((.+?)\\) decorated with @JsonCreator \\(for Enum type (.+?)\\)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/tools/jackson/databind/deser/BasicDeserializerFactory.java","lineNumber":1283,"sourceCode":"                    Class<?> returnType = factory.getRawReturnType();\n                    // usually should be class, but may be just plain Enum<?> (for Enum.valueOf()?)\n                    if (returnType.isAssignableFrom(enumClass)) {\n                        // note: mostly copied from 'EnumDeserializer.deserializerForCreator(...)'\n                        if (factory.getRawParameterType(0) != String.class) {\n                            // [databind#2725]: Should not error out because (1) there may be good creator\n                            //   method and (2) this method may be valid for \"regular\" enum value deserialization\n                            // (leaving aside potential for multiple conflicting creators)\n//                            throw new IllegalArgumentException(\"Parameter #0 type for factory method (\"+factory+\") not suitable, must be java.lang.String\");\n                            continue;\n                        }\n                        if (config.canOverrideAccessModifiers()) {\n                            ClassUtil.checkAndFixAccess(factory.getMember(),\n                                    ctxt.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS));\n                        }\n                        return JDKKeyDeserializers.constructEnumKeyDeserializer(enumRes, factory, byEnumNamingResolver, byToStringResolver, byIndexResolver);\n                    }\n                }\n                throw new IllegalArgumentException(\"Unsuitable method (\"+factory+\") decorated with @JsonCreator (for Enum type \"\n                        +enumClass.getName()+\")\");\n            }\n        }\n        // Also, need to consider @JsonValue, if one found\n        return JDKKeyDeserializers.constructEnumKeyDeserializer(enumRes, byEnumNamingResolver, byToStringResolver, byIndexResolver);\n    }\n\n    /*\n    /**********************************************************************\n    /* DeserializerFactory impl: find explicitly supported types\n    /**********************************************************************\n     */\n\n    /**\n     * Method that can be used to check if databind module has deserializer\n     * for given (likely JDK) type: explicit meaning that it is not automatically\n     * generated for POJO.\n     *<p>","sourceCodeStart":1265,"sourceCodeEnd":1301,"githubUrl":"https://github.com/FasterXML/jackson-databind/blob/a50c7d2a1d57234ac4adf70dbd88ac90db6436e4/src/main/java/tools/jackson/databind/deser/BasicDeserializerFactory.java#L1265-L1301","documentation":"Thrown while building an enum key deserializer when a static factory method annotated with @JsonCreator on an enum does not match the required shape: a single-argument method whose return type is assignable to the enum. Any other arity or an incompatible return type is rejected. (A single non-String argument is silently skipped, not thrown.)","triggerScenarios":"An enum with a @JsonCreator-annotated static factory that takes zero or 2+ arguments, or whose return type isn't assignable to the enum type.","commonSituations":"Annotating a convenience factory with @JsonCreator by mistake; an enum with multiple factories where the wrong one got the annotation; a refactor that changed the factory signature (e.g. adding parameters).","solutions":["Ensure the @JsonCreator static factory takes exactly one parameter and returns the enum type (assignable).","If the method isn't meant to be a JSON creator, remove @JsonCreator from it.","For by-name/fromString semantics, name the method fromJson and annotate a single-String-argument factory with @JsonCreator."],"exampleFix":"// before\npublic enum Color {\n    @JsonCreator static Color fromRgb(int r, int g, int b) { ... } // 3 args -> throws\n}\n// after\npublic enum Color {\n    @JsonCreator static Color fromName(String name) { return Color.valueOf(name.toUpperCase()); }\n}","handlingStrategy":"validation","validationCode":"// Verify the @JsonCreator factory on the enum conforms before deserialization\nMethod m = findJsonCreatorFactory(MyEnum.class);\nif (m == null\n        || m.getParameterCount() != 1\n        || !MyEnum.class.isAssignableFrom(m.getReturnType())) {\n    throw new IllegalStateException(\n        \"@JsonCreator on enum must be single-arg and return the enum type\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Enum @JsonCreator factories: exactly one parameter, return type assignable to the enum.","Reserve @JsonCreator on enums for the canonical fromString(String) factory.","Add a unit test that round-trips every enum value through JSON."],"tags":["enum","jsoncreator","deserialization"],"analyzedSha":"a50c7d2a1d57234ac4adf70dbd88ac90db6436e4","analyzedAt":"2026-08-06T20:31:51.404Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}