HHH-15646 Using a generic DTO i get a ClassCastException: class sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to class java.lang.reflect.ParameterizedType

This commit is contained in:
Andrea Boriero 2022-11-14 12:26:02 +01:00 committed by Andrea Boriero
parent ccf24ac355
commit dd5c455d88
1 changed files with 4 additions and 0 deletions

View File

@ -14,6 +14,7 @@ import java.lang.reflect.Member;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType; import java.lang.reflect.ParameterizedType;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.WildcardType; import java.lang.reflect.WildcardType;
import java.util.Locale; import java.util.Locale;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -867,6 +868,9 @@ public final class ReflectHelper {
else if ( type instanceof ParameterizedType ) { else if ( type instanceof ParameterizedType ) {
return (Class<T>) ( (ParameterizedType) type ).getRawType(); return (Class<T>) ( (ParameterizedType) type ).getRawType();
} }
else if ( type instanceof TypeVariable ) {
return getClass( ( (TypeVariable) type ).getBounds()[0] );
}
else if ( type instanceof WildcardType ) { else if ( type instanceof WildcardType ) {
return getClass( ( (WildcardType) type ).getUpperBounds()[0] ); return getClass( ( (WildcardType) type ).getUpperBounds()[0] );
} }