{"record":{"id":"2570014b787a19ae","repo":"FasterXML/jackson-databind","slug":"cannot-deserialize-class-of-type-as-a-bean","errorCode":null,"errorMessage":"Cannot deserialize Class {} (of type {}) 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/a50c7d2a1d57234ac4adf70dbd88ac90db6436e4/src/main/java/tools/jackson/databind/deser/BeanDeserializerFactory.java#L1050-L1086","documentation":"Thrown by BeanDeserializerFactory.isPotentialBeanType when Jackson is asked to build a bean deserializer for a type that can never be a bean — anything ClassUtil.canBeABeanType flags (arrays, enums, primitives, interfaces, abstract classes, etc.). These need dedicated deserializers, not bean introspection.","triggerScenarios":"Asking the mapper to deserialize into an array type (int[]), an enum, a primitive/primitive-wrapper mismatch, or an interface/abstract class without polymorphic type info — usually because the target JavaType resolved to something non-bean.","commonSituations":"Generic code that passes Class<?> through and lands on a non-bean; type erasure losing the real type; wrong TypeReference; misconfigured @JsonTypeInfo on an interface; passing Object.class or a raw Collection type.","solutions":["Use the correct target type — arrays via mapper.readValue(json, new TypeReference<int[]>(){}), enums via the enum class, etc.","For interfaces/abstract types, enable polymorphic type info (@JsonTypeInfo) or supply a concrete subtype.","Ensure the TypeReference/JavaType carries the intended concrete class, not a raw or erased type."],"exampleFix":"// before\nObject o = mapper.readValue(json, Object.class); // generic erosion -> non-bean path\n// after\nList<Item> items = mapper.readValue(json, new TypeReference<List<Item>>(){});","handlingStrategy":"validation","validationCode":"JavaType t = mapper.constructType(targetTypeReference);\nif (t.isArrayType() || t.isEnumType() || t.isPrimitive()\n        || t.isInterface() || t.isAbstract()) {\n    throw new IllegalArgumentException(\"Target \" + t + \" cannot be deserialized as a bean\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass concrete target types (Class or TypeReference) to readValue.","Avoid raw Class/Object targets in generic deserialization code.","Unit-test deserialization of each top-level type you expose."],"tags":["deserialization","bean","type-mismatch"],"analyzedSha":"a50c7d2a1d57234ac4adf70dbd88ac90db6436e4","analyzedAt":"2026-08-06T20:31:51.404Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}