Relax generic type detection for ResponseEntity
Before this change the getHttpEntityType method in HttpEntityMethodProcessor raised an ISE if the generic type cannot be detected. That made sense for resolving a controller method argument where the target body type is crucial. However for a return value the generic type should not be required since we either have an actual body or no body at all in which case it doesn't even matter. This change relaxes the checks and defaults to Object.class for the ResponseEntity generic type on the return value side. Issue: SPR-14799
This commit is contained in:
parent
a795fd4714
commit
71201e1a43
|
|
@ -121,6 +121,10 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro
|
|||
|
||||
ServletServerHttpRequest inputMessage = createInputMessage(webRequest);
|
||||
Type paramType = getHttpEntityType(parameter);
|
||||
if (paramType == null) {
|
||||
throw new IllegalArgumentException("HttpEntity parameter '" + parameter.getParameterName() +
|
||||
"' in method " + parameter.getMethod() + " is not parameterized");
|
||||
}
|
||||
|
||||
Object body = readWithMessageConverters(webRequest, parameter, paramType);
|
||||
if (RequestEntity.class == parameter.getParameterType()) {
|
||||
|
|
@ -146,8 +150,9 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro
|
|||
else if (parameterType instanceof Class) {
|
||||
return Object.class;
|
||||
}
|
||||
throw new IllegalArgumentException("HttpEntity parameter '" + parameter.getParameterName() +
|
||||
"' in method " + parameter.getMethod() + " is not parameterized");
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -243,6 +248,7 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro
|
|||
}
|
||||
else {
|
||||
Type type = getHttpEntityType(returnType);
|
||||
type = (type != null ? type : Object.class);
|
||||
return ResolvableType.forMethodParameter(returnType, type).resolve(Object.class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue