You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ah. No, this does not and can not work, due to Java Type Erasure.
You need to read about it -- there is no real type information passed with ReturnClass: you are just passing type variable ReturnClass which is not bound to anything by compiler. There must be actual Class involved somewhere.
So: you can construct JavaType or TypeReference on caller side:
TypeReference<?> ref = new TypeReference<FooClass>() { };
// or
JavaType type = mapper.constructType(FooClass.class);
and pass that. But type variables passed can not be used this way, not even via TypeReference. All it knows is that a type variable ought to be there, with bounds of ? extends Object.
There is unfortunately nothing Jackson can do about this.
Per discussion on #921 I am reporting this bug here.
When trying to call ObjectMapper from a templated method, I receive a "ClassCastException: java.util.LinkedHashMap cannot be cast to FooClass"
This is in jackson-databind 2.8.10 in a sample project compiled via Maven.
Sample project can be found here: https://github.com/hubbazoot/object-mapper-demo
Full source code with problem:
The text was updated successfully, but these errors were encountered: