提交 2292e46b 编写于 作者: R Rossen Stoyanchev

Update empty return value ResponseBody handling

When a null is returned from an @ResponseBody method, rather than
returning Mono.empty() immediately, convert it to Mono.empty() and
apply the same processing.

Currently that doesn't make a practical difference but it's more
accurate to do it this way. Eventually it may mean the possibility
to turn empty values into something through an extension point
as we do with ResponseBodyAdvice in Spring MVC today.
上级 91d06389
......@@ -126,23 +126,25 @@ public class ResponseBodyResultHandler implements HandlerResultHandler, Ordered
@SuppressWarnings("unchecked")
public Mono<Void> handleResult(ServerWebExchange exchange, HandlerResult result) {
Optional<Object> value = result.getReturnValue();
if (!value.isPresent()) {
return Mono.empty();
}
Publisher<?> publisher;
ResolvableType elementType;
ResolvableType returnType = result.getReturnValueType();
if (this.conversionService.canConvert(returnType.getRawClass(), Publisher.class)) {
publisher = this.conversionService.convert(value.get(), Publisher.class);
Optional<Object> optionalValue = result.getReturnValue();
if (optionalValue.isPresent()) {
publisher = this.conversionService.convert(optionalValue.get(), Publisher.class);
}
else {
publisher = Mono.empty();
}
elementType = returnType.getGeneric(0);
if (Void.class.equals(elementType.getRawClass())) {
return Mono.from((Publisher<Void>)publisher);
}
}
else {
publisher = Mono.just(value.get());
publisher = Mono.justOrEmpty(result.getReturnValue());
elementType = returnType;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册