From ae9be7ac258ccd4003012b70f0363627a4c4a43f Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Sun, 11 Feb 2018 11:23:36 +0800 Subject: [PATCH] --- src/org/redkale/convert/ObjectDecoder.java | 6 ++-- src/org/redkale/convert/ObjectEncoder.java | 4 +-- src/org/redkale/util/TypeToken.java | 36 +++++++++++++--------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/org/redkale/convert/ObjectDecoder.java b/src/org/redkale/convert/ObjectDecoder.java index ea145d9f4..a0140f6db 100644 --- a/src/org/redkale/convert/ObjectDecoder.java +++ b/src/org/redkale/convert/ObjectDecoder.java @@ -95,7 +95,7 @@ public final class ObjectDecoder implements Decodeable implements Decodeable implements Decodeable implements Encodeable implements Encodeable { public static Type getGenericType(final Type type, final Type declaringClass) { if (type == null || declaringClass == null) return type; if (type instanceof TypeVariable) { + Type superType = null; + Class declaringClass0 = null; if (declaringClass instanceof Class) { - final Class declaringClass0 = (Class) declaringClass; - Type superType = declaringClass0.getGenericSuperclass(); + declaringClass0 = (Class) declaringClass; + superType = declaringClass0.getGenericSuperclass(); while (superType instanceof Class && superType != Object.class) superType = ((Class) superType).getGenericSuperclass(); - if (superType instanceof ParameterizedType) { - ParameterizedType superPT = (ParameterizedType) superType; - Type[] atas = superPT.getActualTypeArguments(); - Class ss = declaringClass0; - TypeVariable[] asts = ss.getTypeParameters(); - while (atas.length != asts.length && ss != Object.class) { - ss = ss.getSuperclass(); - asts = ss.getTypeParameters(); - } - if (atas.length == asts.length) { - for (int i = 0; i < asts.length; i++) { - if (asts[i] == type) return atas[i]; - } + } else if (declaringClass instanceof ParameterizedType) { + superType = declaringClass; + Type rawType = ((ParameterizedType) declaringClass).getRawType(); + if (rawType instanceof Class) declaringClass0 = (Class) rawType; + } + if (declaringClass0 != null && superType instanceof ParameterizedType) { + ParameterizedType superPT = (ParameterizedType) superType; + Type[] atas = superPT.getActualTypeArguments(); + Class ss = declaringClass0; + TypeVariable[] asts = ss.getTypeParameters(); + while (atas.length != asts.length && ss != Object.class) { + ss = ss.getSuperclass(); + asts = ss.getTypeParameters(); + } + if (atas.length == asts.length) { + for (int i = 0; i < asts.length; i++) { + if (asts[i] == type) return atas[i]; } } }