mapper.reader().withType(cl).readValue(bytes);
(cl is a class generated by javassist implementing interfaces: User, Something and extends UserImpl)
Jackson tries to return UserImpl and raise an error:
Failed to narrow type [simple type, class User#proxy1415658051724996000] with concrete-type annotation (value UserImpl), method 'User#proxy1415658051724996000': Class UserImpl is not assignable to User#proxy1415658051724996000
Exception comes from: com.fasterxml.jackson.databind.JavaType:
protected void _assertSubclass(Class<?> subclass, Class<?> superClass) {
if (!_class.isAssignableFrom(subclass)) {
throw new IllegalArgumentException("Class "+subclass.getName()+" is not assignable to "+_class.getName());
}
}
And now the most interesting thing: In my code:
UserImpl.class.isAssignableFrom(cl) returns true!
Maybe I did something wrong and the solution is obvious but I don't see it.
regards,
Marek
--
You received this message because you are subscribed to the Google Groups "jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user...@googlegroups.com.
To post to this group, send email to jackso...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hello,
Tatu, you have absolutely right with mixed arguments in my example. The issue is that isAssignableFrom() returns false even if object assignment is possible.
Here is a simple testcase: https://github.com/nnegativ/jackson-javassist-test
Btw dozer do something like that to detect proxies:public static final String CGLIB_ID = "$$EnhancerByCGLIB$$";public static final String JAVASSIST_ID = "$$_javassist";public static boolean isProxy(Class clazz) {//todo: implement a better way of determining this that is more genericreturn (clazz.getName().indexOf(MapperConstants.CGLIB_ID) >= 0 || clazz.getName().indexOf(MapperConstants.JAVASSIST_ID) >= 0);}Not so pretty, but works (I hope)
Do you think that modify com.fasterxml.jackson.databind.JavaType._assertSubclass()
and use com.fasterxml.jackson.databind.util.ClassUtil.isProxyType(clazz) is a good solution?We could improve isProxyType to handle javassist and cglib (it checks only java and hibernate proxies now).