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-2020 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.
@@ -41,6 +41,7 @@ import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.MessagingException;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.MimeType;
/**
@@ -144,7 +145,7 @@ public abstract class AbstractEncoderMethodReturnValueHandler implements Handler
ResolvableType.forInstance(content) : returnValueType);
}
if (elementType.resolve() == void.class || elementType.resolve() == Void.class) {
if (ClassUtils.isVoidType(elementType.resolve())) {
return Flux.from(publisher).cast(DataBuffer.class);
}

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.
@@ -37,6 +37,7 @@ import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.MimeType;
/**
@@ -119,7 +120,7 @@ final class DefaultRSocketRequester implements RSocketRequester {
}
private static boolean isVoid(ResolvableType elementType) {
return (Void.class.equals(elementType.resolve()) || void.class.equals(elementType.resolve()));
return ClassUtils.isVoidType(elementType.resolve());
}
private DataBufferFactory bufferFactory() {

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.lang.Nullable;
import org.springframework.messaging.rsocket.RSocketRequester;
import org.springframework.messaging.rsocket.RSocketStrategies;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.MimeType;
import org.springframework.util.StringUtils;
import org.springframework.util.StringValueResolver;
@@ -134,9 +135,7 @@ final class RSocketServiceMethod {
Class<?> actualType = actualParam.getNestedParameterType();
Function<RSocketRequestValues, Publisher<?>> responseFunction;
if (actualType.equals(void.class) || actualType.equals(Void.class) ||
(reactiveAdapter != null && reactiveAdapter.isNoValue())) {
if (ClassUtils.isVoidType(actualType) || (reactiveAdapter != null && reactiveAdapter.isNoValue())) {
responseFunction = values -> {
RSocketRequester.RetrieveSpec retrieveSpec = initRequest(requester, values);
return (values.getPayload() == null && values.getPayloadValue() == null ?