forked from loafle/openapi-generator-original
Fix ClassCastException if expected type is Object (#11510)
The currently generated code will throw a `ClassCastException` if `type` is `Object`. I'm not quite sure why `isAssignableFrom` is used here but I tried to keep the change minimal - in my understanding, the result would be the same if the line was ``` if(Types.getRawType(type).equals(ApiResponse.class)) { ``` because the `ApiResponse` only extends `Object` and implements no interfaces. Maybe it was meant to be `ApiResponse.class.isAssignableFrom(Types.getRawType(type))`? This would also permit subclasses of `ApiResponse`, but then it would be more complicated to determine the actual type parameter (because `type` itself may not be parameterized) and to create the object to return (because it would have to be an instance of the subclass).
This commit is contained in:
parent
92ccb629e9
commit
1a14d9e5ca
@ -25,7 +25,7 @@ public class ApiResponseDecoder extends JacksonDecoder {
|
||||
Map<String, Collection<String>> responseHeaders = Collections.unmodifiableMap(response.headers());
|
||||
//Detects if the type is an instance of the parameterized class ApiResponse
|
||||
Type responseBodyType;
|
||||
if (Types.getRawType(type).isAssignableFrom(ApiResponse.class)) {
|
||||
if (type instanceof ParameterizedType && Types.getRawType(type).isAssignableFrom(ApiResponse.class)) {
|
||||
//The ApiResponse class has a single type parameter, the Dto class itself
|
||||
responseBodyType = ((ParameterizedType) type).getActualTypeArguments()[0];
|
||||
Object body = super.decode(response, responseBodyType);
|
||||
|
Loading…
x
Reference in New Issue
Block a user