Menu

#367 ClassCastException when mapping List <?>

Dozer v5.3.2
open
nobody
5
2012-02-15
2012-02-15
No

When trying to map a field with nested generic types like List<? extends A> I get a ClassCastException (WildcardTypeImpl cannot be cast to java.lang.Class)
I think this issue can be handled with the 3487264.
The exception is raised from the method determineGenericsType(Type) in the ReflectionUtils class, because of the following casting:

result = (Class<?>) genericType

I've patched a copy of the class by replacing that line by the following code, but I'm not sure if it is the optimal solution or even a correct approach, though it works for my own purposes:

if (genericType instanceof WildcardType){
result = (Class<?>) ((WildcardType) genericType).getUpperBounds()[0];
} else {
result = (Class<?>) genericType;
}

Discussion


Log in to post a comment.

MongoDB Logo MongoDB