Correctly detect Optional return type for @HttpExchange methods

Prior to this commit, a ClassCastException was thrown for an Optional
return type for an @HttpExchange method. This is because the check for
an Optional return type was based on the type contained in the Optional
instead of the Optional itself.

Closes gh-28493
This commit is contained in:
wonwoo
2022-05-20 13:31:52 +09:00
committed by Sam Brannen
parent 9487e8ce1e
commit 9181ac70f5
2 changed files with 9 additions and 1 deletions

View File

@@ -16,6 +16,8 @@
package org.springframework.web.service.invoker;
import java.util.Optional;
import io.reactivex.rxjava3.core.Completable;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.core.Single;
@@ -131,6 +133,9 @@ public class HttpServiceMethodTests {
String body = service.getBody();
assertThat(body).isEqualTo("requestToBody");
Optional<String> optional = service.getBodyOptional();
assertThat(optional).isEqualTo(Optional.of("requestToBody"));
ResponseEntity<String> entity = service.getEntity();
assertThat(entity.getBody()).isEqualTo("requestToEntity");
@@ -252,6 +257,9 @@ public class HttpServiceMethodTests {
@GetExchange
String getBody();
@GetExchange
Optional<String> getBodyOptional();
@GetExchange
ResponseEntity<Void> getVoidEntity();