1515
1616import feign .Request ;
1717import feign .Response ;
18+ import feign .Types ;
1819import feign .codec .DecodeException ;
1920import feign .codec .Decoder ;
2021import java .io .IOException ;
2122import java .lang .annotation .Annotation ;
2223import java .lang .reflect .Constructor ;
2324import java .lang .reflect .InvocationTargetException ;
25+ import java .lang .reflect .Type ;
2426import java .util .Arrays ;
2527import java .util .Collection ;
2628import java .util .HashMap ;
@@ -46,11 +48,11 @@ class ExceptionGenerator {
4648 private final Integer bodyIndex ;
4749 private final Integer headerMapIndex ;
4850 private final Integer numOfParams ;
49- private final Class bodyType ;
51+ private final Type bodyType ;
5052 private final Class <? extends Exception > exceptionType ;
5153 private final Decoder bodyDecoder ;
5254
53- ExceptionGenerator (Integer bodyIndex , Integer headerMapIndex , Integer numOfParams , Class bodyType ,
55+ ExceptionGenerator (Integer bodyIndex , Integer headerMapIndex , Integer numOfParams , Type bodyType ,
5456 Class <? extends Exception > exceptionType , Decoder bodyDecoder ) {
5557 this .bodyIndex = bodyIndex ;
5658 this .headerMapIndex = headerMapIndex ;
@@ -67,7 +69,7 @@ Exception createException(Response response) throws InvocationTargetException,
6769 Class <?>[] paramClasses = new Class [numOfParams ];
6870 Object [] paramValues = new Object [numOfParams ];
6971 if (bodyIndex >= 0 ) {
70- paramClasses [bodyIndex ] = bodyType ;
72+ paramClasses [bodyIndex ] = Types . getRawType ( bodyType ) ;
7173 paramValues [bodyIndex ] = resolveBody (response );
7274 }
7375 if (headerMapIndex >= 0 ) {
@@ -84,7 +86,7 @@ Class<? extends Exception> getExceptionType() {
8486 }
8587
8688 private Object resolveBody (Response response ) {
87- if (bodyType . getClass (). equals ( Response . class )) {
89+ if (bodyType instanceof Class <?> && (( Class <?>) bodyType ). isInstance ( response )) {
8890 return response ;
8991 }
9092 try {
@@ -114,13 +116,13 @@ public Builder withResponseBodyDecoder(Decoder bodyDecoder) {
114116
115117 public ExceptionGenerator build () {
116118 Constructor <? extends Exception > constructor = getConstructor (exceptionType );
117- Class <?> [] parameterTypes = constructor .getParameterTypes ();
119+ Type [] parameterTypes = constructor .getGenericParameterTypes ();
118120 Annotation [][] parametersAnnotations = constructor .getParameterAnnotations ();
119121
120122 Integer bodyIndex = -1 ;
121123 Integer headerMapIndex = -1 ;
122124 Integer numOfParams = parameterTypes .length ;
123- Class bodyType = null ;
125+ Type bodyType = null ;
124126
125127 for (int i = 0 ; i < parameterTypes .length ; i ++) {
126128 Annotation [] paramAnnotations = parametersAnnotations [i ];
@@ -129,7 +131,7 @@ public ExceptionGenerator build() {
129131 if (annotation .annotationType ().equals (ResponseHeaders .class )) {
130132 checkState (headerMapIndex == -1 ,
131133 "Cannot have two parameters tagged with @ResponseHeaders" );
132- checkState (parameterTypes [i ].equals (Map .class ),
134+ checkState (Types . getRawType ( parameterTypes [i ]) .equals (Map .class ),
133135 "Response Header map must be of type Map, but was %s" , parameterTypes [i ]);
134136 headerMapIndex = i ;
135137 foundAnnotation = true ;
0 commit comments