完善Rest的泛型识别

This commit is contained in:
Redkale
2020-08-06 16:06:46 +08:00
parent abb790da54
commit 1f27d5f3e3
2 changed files with 11 additions and 1 deletions

View File

@@ -1158,7 +1158,8 @@ public final class Rest {
}
} while ((loop = loop.getSuperclass()) != Object.class);
}
paramlist.add(new Object[]{param, n, ptype, radix, comment, required, annpara, annsid, annaddr, annhead, anncookie, annbody, annfile, annuri, userid, annheaders, param.getParameterizedType()});
java.lang.reflect.Type paramtype = TypeToken.getGenericType( param.getParameterizedType(),serviceType);
paramlist.add(new Object[]{param, n, ptype, radix, comment, required, annpara, annsid, annaddr, annhead, anncookie, annbody, annfile, annuri, userid, annheaders, paramtype});
}
Map<String, Object> mappingMap = new LinkedHashMap<>();

View File

@@ -151,6 +151,7 @@ public abstract class TypeToken<T> {
ss = ss.getSuperclass();
asts = ss.getTypeParameters();
}
if (atas.length == asts.length) {
for (int i = 0; i < asts.length; i++) {
Type currt = asts[i];
@@ -185,6 +186,14 @@ public abstract class TypeToken<T> {
&& ((TypeVariable) type).getBounds()[0] instanceof Class
&& ((Class) ((TypeVariable) type).getBounds()[0]).isAssignableFrom((Class) atas[i]))
return atas[i];
if (atas[i] instanceof Class
&& ((TypeVariable) type).getBounds().length == 1
&& ((TypeVariable) type).getBounds()[0] instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) ((TypeVariable) type).getBounds()[0];
if (pt.getRawType() instanceof Class && ((Class) pt.getRawType()).isAssignableFrom((Class) atas[i])) {
return atas[i];
}
}
if (atas[i] instanceof ParameterizedType
&& ((TypeVariable) type).getBounds().length == 1
&& ((TypeVariable) type).getBounds()[0] == Object.class)