ResponseEntity declared as Object in WebFlux controller

Issue: SPR-15785
This commit is contained in:
Rossen Stoyanchev
2017-07-18 17:09:24 +02:00
parent 57221ab15c
commit 56903581d9
3 changed files with 29 additions and 4 deletions

View File

@@ -92,15 +92,18 @@ public class HandlerResult {
}
/**
* Return the type of the value returned from the handler.
* Return the type of the value returned from the handler -- e.g. the return
* type declared on a controller method's signature. Also see
* {@link #getReturnTypeSource()} to obtain the underlying
* {@link MethodParameter} for the return type.
*/
public ResolvableType getReturnType() {
return this.returnType;
}
/**
* Return the {@link MethodParameter} from which
* {@link #getReturnType() returnType} was created.
* Return the {@link MethodParameter} from which {@link #getReturnType()
* returnType} was created.
*/
public MethodParameter getReturnTypeSource() {
return (MethodParameter) this.returnType.getSource();

View File

@@ -80,7 +80,8 @@ public class ResponseEntityResultHandler extends AbstractMessageWriterResultHand
@Override
public boolean supports(HandlerResult result) {
if (isSupportedType(result.getReturnType().getRawClass())) {
Class<?> valueType = resolveReturnValueType(result);
if (isSupportedType(valueType)) {
return true;
}
ReactiveAdapter adapter = getAdapter(result);
@@ -88,6 +89,16 @@ public class ResponseEntityResultHandler extends AbstractMessageWriterResultHand
isSupportedType(result.getReturnType().getGeneric().resolve(Object.class));
}
@Nullable
private static Class<?> resolveReturnValueType(HandlerResult result) {
Class<?> valueType = result.getReturnType().getRawClass();
Object value = result.getReturnValue();
if ((valueType == null || valueType.equals(Object.class)) && value != null) {
valueType = value.getClass();
}
return valueType;
}
private boolean isSupportedType(@Nullable Class<?> clazz) {
return (clazz != null && HttpEntity.class.isAssignableFrom(clazz) &&
!RequestEntity.class.isAssignableFrom(clazz));