{"record":{"id":"49aaf3f9e244129c","repo":"FasterXML/jackson-databind","slug":"cannot-deserialize-class-type-getname-of-typ","errorCode":null,"errorMessage":"Cannot deserialize Class ${type.getName()} (of type ${typeStr}) as a Bean","messagePattern":"Cannot deserialize Class (.+?) \\(of type (.+?)\\) as a Bean","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/tools/jackson/databind/deser/BeanDeserializerFactory.java","lineNumber":1068,"sourceCode":"    /*\n    /**********************************************************\n    /* Helper methods for Bean deserializer, other\n    /**********************************************************\n     */\n\n    /**\n     * Helper method used to skip processing for types that we know\n     * cannot be (i.e. are never consider to be) beans:\n     * things like primitives, Arrays, Enums, and proxy types.\n     *<p>\n     * Note that usually we shouldn't really be getting these sort of\n     * types anyway; but better safe than sorry.\n     */\n    protected boolean isPotentialBeanType(Class<?> type)\n    {\n        String typeStr = ClassUtil.canBeABeanType(type);\n        if (typeStr != null) {\n            throw new IllegalArgumentException(\"Cannot deserialize Class \"+type.getName()+\" (of type \"+typeStr+\") as a Bean\");\n        }\n        if (ClassUtil.isProxyType(type)) {\n            throw new IllegalArgumentException(\"Cannot deserialize Proxy class \"+type.getName()+\" as a Bean\");\n        }\n        // [databind#3229]: Local/anonymous classes cannot be instantiated but\n        //   can still be updated via `readerForUpdating()`. So let them through\n        //   here; if actual instantiation is attempted, `ValueInstantiator` will\n        //   fail with a clear error.\n        return true;\n    }\n\n    /**\n     * Helper method that will check whether given raw type is marked as always ignorable\n     * (for purpose of ignoring properties with type)\n     */\n    protected boolean isIgnorableType(DeserializationContext ctxt, BeanPropertyDefinition propDef,\n            Class<?> type, Map<Class<?>,Boolean> ignoredTypes)\n    {","sourceCodeStart":1050,"sourceCodeEnd":1086,"githubUrl":"https://github.com/FasterXML/jackson-databind/blob/87876ca5c0569b4933aec2d30d6225e4b9ba3a43/src/main/java/tools/jackson/databind/deser/BeanDeserializerFactory.java#L1050-L1086","documentation":"Thrown by BeanDeserializerFactory.isPotentialBeanType when the type cannot be a bean per ClassUtil.canBeABeanType (returns a non-null category string, e.g. for arrays, primitives, enums, or other non-bean categories). The bean deserializer factory only handles POJO-style beans and rejects types that should be handled by other deserializers.","triggerScenarios":"Routing a non-bean type (array, enum, primitive wrapper category flagged by canBeABeanType, etc.) into the bean deserialization path -- typically by forcing a bean deserializer, a misconfigured custom type, or an introspector that redirects the wrong type.","commonSituations":"Trying to readValue an array or enum into a bean-shaped class; a custom AbstractTypeResolver mapping a bean type to an array/enum; incorrect @JsonDeserialize on a type that is not a bean; framework glue that forces bean handling on JDK types.","solutions":["Use the correct target type (List/array for array JSON, the enum class for enum values, etc.) instead of forcing bean deserialization.","Remove/fix custom AbstractTypeResolver or @JsonDeserialize that routes a non-bean type to the bean factory.","If you have a custom value type, ensure it is a genuine POJO (not an array/enum/primitive category)."],"exampleFix":"// before: trying to deserialize JSON array into a bean\nclass Wrapper { int x; }\nWrapper w = mapper.readValue(\"[1,2,3]\", Wrapper.class);\n\n// after: use the right target type\nList<Integer> vals = mapper.readValue(\"[1,2,3]\", new TypeReference<List<Integer>>(){});","handlingStrategy":"type-guard","validationCode":"Class<?> type = Target.class;\nif (type.isArray() || type.isEnum() || type.isPrimitive() || ClassUtil.canBeABeanType(type) != null) {\n    throw new IllegalArgumentException(type + \" is not a bean type\");\n}\nmapper.readValue(json, type);","typeGuard":"boolean isBeanType(Class<?> c) {\n    return !c.isArray() && !c.isEnum() && !c.isPrimitive()\n        && ClassUtil.canBeABeanType(c) == null;\n}","tryCatchPattern":null,"preventionTips":["Match the target type to the JSON shape (arrays -> List/array, enums -> enum class).","Do not route non-bean types through the bean deserializer via custom resolvers.","Unit-test mapper binding for each target type."],"tags":["jackson","deserialization","bean","type-mismatch","config"],"backgroundTag":null,"analyzedSha":"87876ca5c0569b4933aec2d30d6225e4b9ba3a43","analyzedAt":"2026-08-11T12:55:24.033Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}