HTTP Service proxy sets body type
Closes gh-34793
This commit is contained in:
@@ -22,7 +22,9 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.net.URI;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -267,6 +269,19 @@ class RestClientAdapterTests {
|
||||
assertThat(this.anotherServer.getRequestCount()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@ParameterizedAdapterTest // gh-34793
|
||||
void postSet(MockWebServer server, Service service) throws InterruptedException {
|
||||
Set<Person> persons = new LinkedHashSet<>();
|
||||
persons.add(new Person("John"));
|
||||
persons.add(new Person("Richard"));
|
||||
service.postPersonSet(persons);
|
||||
|
||||
RecordedRequest request = server.takeRequest();
|
||||
assertThat(request.getMethod()).isEqualTo("POST");
|
||||
assertThat(request.getPath()).isEqualTo("/persons");
|
||||
assertThat(request.getBody().readUtf8()).isEqualTo("[{\"name\":\"John\"},{\"name\":\"Richard\"}]");
|
||||
}
|
||||
|
||||
|
||||
private static MockWebServer anotherServer() {
|
||||
MockWebServer server = new MockWebServer();
|
||||
@@ -297,6 +312,9 @@ class RestClientAdapterTests {
|
||||
@PostExchange
|
||||
void postMultipart(MultipartFile file, @RequestPart String anotherPart);
|
||||
|
||||
@PostExchange(url = "/persons", contentType = MediaType.APPLICATION_JSON_VALUE)
|
||||
void postPersonSet(@RequestBody Set<Person> set);
|
||||
|
||||
@PutExchange
|
||||
void putWithCookies(@CookieValue String firstCookie, @CookieValue String secondCookie);
|
||||
|
||||
@@ -315,4 +333,19 @@ class RestClientAdapterTests {
|
||||
ResponseEntity<String> getWithIgnoredUriBuilderFactory(URI uri, UriBuilderFactory uriBuilderFactory);
|
||||
}
|
||||
|
||||
|
||||
static final class Person {
|
||||
|
||||
private final String name;
|
||||
|
||||
Person(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
* Copyright 2002-2025 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.
|
||||
@@ -54,6 +54,7 @@ class RequestBodyArgumentResolverTests {
|
||||
this.service.execute(body);
|
||||
|
||||
assertThat(getBodyValue()).isEqualTo(body);
|
||||
assertThat(getBodyValueType()).isEqualTo(new ParameterizedTypeReference<String>() {});
|
||||
assertThat(getPublisherBody()).isNull();
|
||||
}
|
||||
|
||||
@@ -173,6 +174,11 @@ class RequestBodyArgumentResolverTests {
|
||||
return getReactiveRequestValues().getBodyValue();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ParameterizedTypeReference<?> getBodyValueType() {
|
||||
return getReactiveRequestValues().getBodyValueType();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Publisher<?> getPublisherBody() {
|
||||
return getReactiveRequestValues().getBodyPublisher();
|
||||
|
||||
Reference in New Issue
Block a user