Introduce ClassUtils.isVoidType() utility method

This commit is contained in:
Sam Brannen
2024-01-30 16:27:34 +01:00
parent 398cc01650
commit 067638ae6e
8 changed files with 32 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,6 +38,7 @@ import org.springframework.http.codec.HttpMessageWriter;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.web.reactive.HandlerMapping;
import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
@@ -155,7 +156,7 @@ public abstract class AbstractMessageWriterResultHandler extends HandlerResultHa
}
}
if (elementType.resolve() == void.class || elementType.resolve() == Void.class) {
if (ClassUtils.isVoidType(elementType.resolve())) {
return Mono.from((Publisher<Void>) publisher);
}

View File

@@ -39,6 +39,7 @@ import org.springframework.http.HttpStatusCode;
import org.springframework.http.MediaType;
import org.springframework.lang.Nullable;
import org.springframework.ui.Model;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.reactive.BindingContext;
@@ -202,7 +203,7 @@ public class ViewResolutionResultHandler extends HandlerResultHandlerSupport imp
clazz = returnValue.getClass();
}
if (returnValue == NO_VALUE || clazz == void.class || clazz == Void.class) {
if (returnValue == NO_VALUE || ClassUtils.isVoidType(clazz)) {
viewsMono = resolveViews(getDefaultViewName(exchange), locale);
}
else if (CharSequence.class.isAssignableFrom(clazz) && !hasModelAnnotation(parameter)) {