FasterXML/jackson-databind · error · IllegalArgumentException

Cannot deserialize Class ${type.getName()} (of type ${typeSt

Error message

Cannot deserialize Class ${type.getName()} (of type ${typeStr}) as a Bean

What it means

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.

Source

Thrown at src/main/java/tools/jackson/databind/deser/BeanDeserializerFactory.java:1068

    /*
    /**********************************************************
    /* Helper methods for Bean deserializer, other
    /**********************************************************
     */

    /**
     * Helper method used to skip processing for types that we know
     * cannot be (i.e. are never consider to be) beans:
     * things like primitives, Arrays, Enums, and proxy types.
     *<p>
     * Note that usually we shouldn't really be getting these sort of
     * types anyway; but better safe than sorry.
     */
    protected boolean isPotentialBeanType(Class<?> type)
    {
        String typeStr = ClassUtil.canBeABeanType(type);
        if (typeStr != null) {
            throw new IllegalArgumentException("Cannot deserialize Class "+type.getName()+" (of type "+typeStr+") as a Bean");
        }
        if (ClassUtil.isProxyType(type)) {
            throw new IllegalArgumentException("Cannot deserialize Proxy class "+type.getName()+" as a Bean");
        }
        // [databind#3229]: Local/anonymous classes cannot be instantiated but
        //   can still be updated via `readerForUpdating()`. So let them through
        //   here; if actual instantiation is attempted, `ValueInstantiator` will
        //   fail with a clear error.
        return true;
    }

    /**
     * Helper method that will check whether given raw type is marked as always ignorable
     * (for purpose of ignoring properties with type)
     */
    protected boolean isIgnorableType(DeserializationContext ctxt, BeanPropertyDefinition propDef,
            Class<?> type, Map<Class<?>,Boolean> ignoredTypes)
    {

View on GitHub (pinned to 87876ca5c0)

Solutions

  1. Use the correct target type (List/array for array JSON, the enum class for enum values, etc.) instead of forcing bean deserialization.
  2. Remove/fix custom AbstractTypeResolver or @JsonDeserialize that routes a non-bean type to the bean factory.
  3. If you have a custom value type, ensure it is a genuine POJO (not an array/enum/primitive category).

Example fix

// before: trying to deserialize JSON array into a bean
class Wrapper { int x; }
Wrapper w = mapper.readValue("[1,2,3]", Wrapper.class);

// after: use the right target type
List<Integer> vals = mapper.readValue("[1,2,3]", new TypeReference<List<Integer>>(){});
Defensive patterns

Strategy: type-guard

Validate before calling

Class<?> type = Target.class;
if (type.isArray() || type.isEnum() || type.isPrimitive() || ClassUtil.canBeABeanType(type) != null) {
    throw new IllegalArgumentException(type + " is not a bean type");
}
mapper.readValue(json, type);

Type guard

boolean isBeanType(Class<?> c) {
    return !c.isArray() && !c.isEnum() && !c.isPrimitive()
        && ClassUtil.canBeABeanType(c) == null;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of FasterXML/jackson-databind@87876ca5c0 (2026-08-11). Data as JSON: /api/errors/49aaf3f9e244129c. Report an issue: GitHub.