15
15
16
16
import feign .Request ;
17
17
import feign .Response ;
18
+ import feign .Types ;
18
19
import feign .codec .DecodeException ;
19
20
import feign .codec .Decoder ;
20
21
import java .io .IOException ;
21
22
import java .lang .annotation .Annotation ;
22
23
import java .lang .reflect .Constructor ;
23
24
import java .lang .reflect .InvocationTargetException ;
25
+ import java .lang .reflect .Type ;
24
26
import java .util .Arrays ;
25
27
import java .util .Collection ;
26
28
import java .util .HashMap ;
@@ -46,11 +48,11 @@ class ExceptionGenerator {
46
48
private final Integer bodyIndex ;
47
49
private final Integer headerMapIndex ;
48
50
private final Integer numOfParams ;
49
- private final Class bodyType ;
51
+ private final Type bodyType ;
50
52
private final Class <? extends Exception > exceptionType ;
51
53
private final Decoder bodyDecoder ;
52
54
53
- ExceptionGenerator (Integer bodyIndex , Integer headerMapIndex , Integer numOfParams , Class bodyType ,
55
+ ExceptionGenerator (Integer bodyIndex , Integer headerMapIndex , Integer numOfParams , Type bodyType ,
54
56
Class <? extends Exception > exceptionType , Decoder bodyDecoder ) {
55
57
this .bodyIndex = bodyIndex ;
56
58
this .headerMapIndex = headerMapIndex ;
@@ -67,7 +69,7 @@ Exception createException(Response response) throws InvocationTargetException,
67
69
Class <?>[] paramClasses = new Class [numOfParams ];
68
70
Object [] paramValues = new Object [numOfParams ];
69
71
if (bodyIndex >= 0 ) {
70
- paramClasses [bodyIndex ] = bodyType ;
72
+ paramClasses [bodyIndex ] = Types . getRawType ( bodyType ) ;
71
73
paramValues [bodyIndex ] = resolveBody (response );
72
74
}
73
75
if (headerMapIndex >= 0 ) {
@@ -84,7 +86,7 @@ Class<? extends Exception> getExceptionType() {
84
86
}
85
87
86
88
private Object resolveBody (Response response ) {
87
- if (bodyType . getClass (). equals ( Response . class )) {
89
+ if (bodyType instanceof Class <?> && (( Class <?>) bodyType ). isInstance ( response )) {
88
90
return response ;
89
91
}
90
92
try {
@@ -114,13 +116,13 @@ public Builder withResponseBodyDecoder(Decoder bodyDecoder) {
114
116
115
117
public ExceptionGenerator build () {
116
118
Constructor <? extends Exception > constructor = getConstructor (exceptionType );
117
- Class <?> [] parameterTypes = constructor .getParameterTypes ();
119
+ Type [] parameterTypes = constructor .getGenericParameterTypes ();
118
120
Annotation [][] parametersAnnotations = constructor .getParameterAnnotations ();
119
121
120
122
Integer bodyIndex = -1 ;
121
123
Integer headerMapIndex = -1 ;
122
124
Integer numOfParams = parameterTypes .length ;
123
- Class bodyType = null ;
125
+ Type bodyType = null ;
124
126
125
127
for (int i = 0 ; i < parameterTypes .length ; i ++) {
126
128
Annotation [] paramAnnotations = parametersAnnotations [i ];
@@ -129,7 +131,7 @@ public ExceptionGenerator build() {
129
131
if (annotation .annotationType ().equals (ResponseHeaders .class )) {
130
132
checkState (headerMapIndex == -1 ,
131
133
"Cannot have two parameters tagged with @ResponseHeaders" );
132
- checkState (parameterTypes [i ].equals (Map .class ),
134
+ checkState (Types . getRawType ( parameterTypes [i ]) .equals (Map .class ),
133
135
"Response Header map must be of type Map, but was %s" , parameterTypes [i ]);
134
136
headerMapIndex = i ;
135
137
foundAnnotation = true ;
0 commit comments