The commit deprecates syncBody(Object) in favor of body(Object)
which has the same behavior in ServerResponse, WebClient and
WebTestClient. It also adds body(Object, Class) and
body(Object, ParameterizedTypeReference) methods in order to support
any reactive type that can be adapted to a Publisher via
ReactiveAdapterRegistry. Related BodyInserters#fromProducer
methods are provided as well.
Shadowed Kotlin body<T>() extensions are deprecated in favor of
bodyWithType<T>() ones, including dedicated Publisher<T> and
Flow<T> variants. Coroutines extensions are adapted as well, and
body(Object) can now be used with suspending functions.
Closes gh-23212
Assert.isNull(registry.getAdapter(body.getClass()),"'body' should be an object, for reactive types use a variant specifying a publisher/producer and its related element type");
@ -61,7 +61,7 @@ public class MultipartIntegrationTests extends AbstractRouterFunctionIntegration
@@ -61,7 +61,7 @@ public class MultipartIntegrationTests extends AbstractRouterFunctionIntegration
@ -75,7 +75,7 @@ public class MultipartIntegrationTests extends AbstractRouterFunctionIntegration
@@ -75,7 +75,7 @@ public class MultipartIntegrationTests extends AbstractRouterFunctionIntegration
Mono<ClientResponse>result=webClient
.post()
.uri("http://localhost:"+this.port+"/parts")
.syncBody(generateBody())
.body(generateBody())
.exchange();
StepVerifier
@ -89,7 +89,7 @@ public class MultipartIntegrationTests extends AbstractRouterFunctionIntegration
@@ -89,7 +89,7 @@ public class MultipartIntegrationTests extends AbstractRouterFunctionIntegration
Mono<String>result=webClient
.post()
.uri("http://localhost:"+this.port+"/transferTo")
.syncBody(generateBody())
.body(generateBody())
.retrieve()
.bodyToMono(String.class);
@ -169,7 +169,7 @@ public class MultipartIntegrationTests extends AbstractRouterFunctionIntegration
@@ -169,7 +169,7 @@ public class MultipartIntegrationTests extends AbstractRouterFunctionIntegration
@ -33,8 +33,8 @@ public class InvalidHttpMethodIntegrationTests extends AbstractRouterFunctionInt
@@ -33,8 +33,8 @@ public class InvalidHttpMethodIntegrationTests extends AbstractRouterFunctionInt
@ -125,7 +125,7 @@ public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrati
@@ -125,7 +125,7 @@ public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrati
@ -85,7 +85,7 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
@@ -85,7 +85,7 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
Mono<ClientResponse>result=webClient
.post()
.uri("/requestPart")
.syncBody(generateBody())
.body(generateBody())
.exchange();
StepVerifier
@ -99,7 +99,7 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
@@ -99,7 +99,7 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
Mono<String>result=webClient
.post()
.uri("/requestBodyMap")
.syncBody(generateBody())
.body(generateBody())
.retrieve()
.bodyToMono(String.class);
@ -113,7 +113,7 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
@@ -113,7 +113,7 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
Mono<String>result=webClient
.post()
.uri("/requestBodyFlux")
.syncBody(generateBody())
.body(generateBody())
.retrieve()
.bodyToMono(String.class);
@ -127,7 +127,7 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
@@ -127,7 +127,7 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
Mono<String>result=webClient
.post()
.uri("/filePartFlux")
.syncBody(generateBody())
.body(generateBody())
.retrieve()
.bodyToMono(String.class);
@ -141,7 +141,7 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
@@ -141,7 +141,7 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
Mono<String>result=webClient
.post()
.uri("/filePartMono")
.syncBody(generateBody())
.body(generateBody())
.retrieve()
.bodyToMono(String.class);
@ -155,7 +155,7 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
@@ -155,7 +155,7 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
Flux<String>result=webClient
.post()
.uri("/transferTo")
.syncBody(generateBody())
.body(generateBody())
.retrieve()
.bodyToFlux(String.class);
@ -183,7 +183,7 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
@@ -183,7 +183,7 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
@ -318,7 +318,8 @@ is closed and is not placed back in the pool.
@@ -318,7 +318,8 @@ is closed and is not placed back in the pool.
[[webflux-client-body]]
== Request Body
The request body can be encoded from an `Object`, as the following example shows:
The request body can be encoded from any asynchronous type handled by `ReactiveAdapterRegistry`,
like `Mono` as the following example shows:
[source,java,intent=0]
[subs="verbatim,quotes"]
@ -348,7 +349,7 @@ You can also have a stream of objects be encoded, as the following example shows
@@ -348,7 +349,7 @@ You can also have a stream of objects be encoded, as the following example shows
.bodyToMono(Void.class);
----
Alternatively, if you have the actual value, you can use the `syncBody` shortcut method,
Alternatively, if you have the actual value, you can use the `body` shortcut method,
as the following example shows:
[source,java,intent=0]
@ -359,7 +360,7 @@ as the following example shows:
@@ -359,7 +360,7 @@ as the following example shows:
Mono<Void> result = client.post()
.uri("/persons/{id}", id)
.contentType(MediaType.APPLICATION_JSON)
.syncBody(person)
.body(person)
.retrieve()
.bodyToMono(Void.class);
----
@ -380,7 +381,7 @@ content is automatically set to `application/x-www-form-urlencoded` by the
@@ -380,7 +381,7 @@ content is automatically set to `application/x-www-form-urlencoded` by the
Mono<Void> result = client.post()
.uri("/path", id)
.syncBody(formData)
.body(formData)
.retrieve()
.bodyToMono(Void.class);
----
@ -428,7 +429,7 @@ explicitly provide the `MediaType` to use for each part through one of the overl
@@ -428,7 +429,7 @@ explicitly provide the `MediaType` to use for each part through one of the overl
builder `part` methods.
Once a `MultiValueMap` is prepared, the easiest way to pass it to the the `WebClient` is
through the `syncBody` method, as the following example shows:
through the `body` method, as the following example shows:
[source,java,intent=0]
[subs="verbatim,quotes"]
@ -437,7 +438,7 @@ through the `syncBody` method, as the following example shows:
@@ -437,7 +438,7 @@ through the `syncBody` method, as the following example shows: