FasterXML/jackson-databind · error · IllegalArgumentException
Cannot deserialize Proxy class ${type.getName()} as a Bean
Error message
Cannot deserialize Proxy class ${type.getName()} as a Bean What it means
Thrown by BeanDeserializerFactory.isPotentialBeanType when the target class is a JDK dynamic proxy (ClassUtil.isProxyType true -- class name starts with the proxy prefix). Jackson cannot instantiate or populate a java.lang.reflect.Proxy-backed class as a bean because its invocation handler is opaque, so it rejects it up front.
Source
Thrown at src/main/java/tools/jackson/databind/deser/BeanDeserializerFactory.java:1071
/**********************************************************
*/
/**
* 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)
{
Boolean status = ignoredTypes.get(type);
if (status != null) {
return status.booleanValue();View on GitHub (pinned to 87876ca5c0)
Solutions
- Deserialize into a concrete POJO class (the un-proxied class), not the proxy class.
- Unwrap the proxy (e.g. Spring's AopProxyUtils.getSingletonTarget / HibernateProxyHelper) before serializing/deserializing.
- Register a mix-in or custom deserializer that targets the real class behind the proxy.
- Avoid using proxy classes as Jackson target types; use the real interface/implementation.
Example fix
// before: target is a proxied class Object read = mapper.readValue(json, proxiedInstance.getClass()); // after: target the real class behind the proxy Class<?> real = AopProxyUtils.proxiedUserInterfaces(proxiedInstance)[0]; Object read = mapper.readValue(json, real);
Defensive patterns
Strategy: type-guard
Validate before calling
Class<?> type = instance.getClass();
if (ClassUtil.isProxyType(type)) {
throw new IllegalArgumentException(type + " is a Proxy; use the real class");
}
mapper.readValue(json, type); Type guard
boolean isProxiable(Class<?> c) {
return !ClassUtil.isProxyType(c);
} Prevention
- Deserialize into concrete POJO classes, not proxy classes.
- Unwrap framework proxies (Spring/Hibernate) before binding.
- Register mixins targeting the real interface/class.
When it happens
Trigger: Calling readValue(..., MyClass.class) (or forcing bean deserialization) where the runtime class is a Proxy generated by java.lang.reflect.Proxy, or a custom AbstractTypeResolver/introspector pointing at a proxy class.
Common situations: Passing a proxy instance's class (e.g., from a framework AOP/interceptor) as the target type; binding to an interface that has been proxied; Spring/Hibernate proxies leaking into Jackson as target types.
Related errors
- Cannot deserialize Class ${type.getName()} (of type ${typeSt
- Duplicate property '${prop.getName()}' for ${_beanDescRef.ge
- _anySetter already set to non-null
- Invalid Object Id definition for %s: cannot find property wi
- Cannot pass null modifier
AI-assisted analysis of FasterXML/jackson-databind@87876ca5c0 (2026-08-11).
Data as JSON: /api/errors/682f4d69d225467b.
Report an issue: GitHub.