diff --git a/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/client/WebClientExtensions.kt b/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/client/WebClientExtensions.kt index 399da10c719..211363fb260 100644 --- a/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/client/WebClientExtensions.kt +++ b/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/client/WebClientExtensions.kt @@ -35,49 +35,35 @@ import reactor.core.publisher.Mono * @author Sebastien Deleuze * @since 5.0 */ -@Deprecated("Use 'bodyWithType' instead.", replaceWith = ReplaceWith("bodyWithType(publisher)")) @Suppress("EXTENSION_SHADOWED_BY_MEMBER") inline fun > RequestBodySpec.body(publisher: S): RequestHeadersSpec<*> = body(publisher, object : ParameterizedTypeReference() {}) /** - * Extension for [WebClient.RequestBodySpec.body] providing a `bodyWithType(Any)` variant + * Extension for [WebClient.RequestBodySpec.body] providing a `body(Flow)` variant * leveraging Kotlin reified type parameters. This extension is not subject to type * erasure and retains actual generic type arguments. - * @param producer the producer to write to the request. This must be a - * [Publisher] or another producer adaptable to a - * [Publisher] via [org.springframework.core.ReactiveAdapterRegistry] - * @param the type of the elements contained in the producer - * @author Sebastien Deleuze - * @since 5.2 - */ -inline fun RequestBodySpec.bodyWithType(producer: Any): RequestHeadersSpec<*> = - body(producer, object : ParameterizedTypeReference() {}) - -/** - * Extension for [WebClient.RequestBodySpec.body] providing a `bodyWithType(Publisher)` variant - * leveraging Kotlin reified type parameters. This extension is not subject to type - * erasure and retains actual generic type arguments. - * @param publisher the [Publisher] to write to the request - * @param the type of the elements contained in the publisher + * @param flow the [Flow] to write to the request + * @param the type of the elements contained in the flow * @author Sebastien Deleuze * @since 5.2 */ -inline fun RequestBodySpec.bodyWithType(publisher: Publisher): RequestHeadersSpec<*> = - body(publisher, object : ParameterizedTypeReference() {}) +inline fun RequestBodySpec.body(flow: Flow): RequestHeadersSpec<*> = + body(flow, object : ParameterizedTypeReference() {}) /** - * Extension for [WebClient.RequestBodySpec.body] providing a `bodyWithType(Flow)` variant + * Extension for [WebClient.RequestBodySpec.body] providing a `body(Any)` variant * leveraging Kotlin reified type parameters. This extension is not subject to type * erasure and retains actual generic type arguments. - * @param flow the [Flow] to write to the request - * @param the type of the elements contained in the flow + * @param producer the producer to write to the request. This must be a + * [Publisher] or another producer adaptable to a + * [Publisher] via [org.springframework.core.ReactiveAdapterRegistry] + * @param the type of the elements contained in the producer * @author Sebastien Deleuze * @since 5.2 */ -@ExperimentalCoroutinesApi -inline fun RequestBodySpec.bodyWithType(flow: Flow): RequestHeadersSpec<*> = - body(flow, object : ParameterizedTypeReference() {}) +inline fun RequestBodySpec.body(producer: Any): RequestHeadersSpec<*> = + body(producer, object : ParameterizedTypeReference() {}) /** * Coroutines variant of [WebClient.RequestHeadersSpec.exchange]. diff --git a/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/ServerResponseExtensions.kt b/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/ServerResponseExtensions.kt index 12cfdef9647..726986633ae 100644 --- a/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/ServerResponseExtensions.kt +++ b/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/ServerResponseExtensions.kt @@ -32,13 +32,12 @@ import reactor.core.publisher.Mono * @author Sebastien Deleuze * @since 5.0 */ -@Deprecated("Use 'bodyWithType' instead.", replaceWith = ReplaceWith("bodyWithType(publisher)")) @Suppress("EXTENSION_SHADOWED_BY_MEMBER") inline fun ServerResponse.BodyBuilder.body(publisher: Publisher): Mono = body(publisher, object : ParameterizedTypeReference() {}) /** - * Extension for [ServerResponse.BodyBuilder.body] providing a `bodyWithType(Any)` variant + * Extension for [ServerResponse.BodyBuilder.body] providing a `body(Any)` variant * leveraging Kotlin reified type parameters. This extension is not subject to type * erasure and retains actual generic type arguments. * @param producer the producer to write to the response. This must be a @@ -48,21 +47,9 @@ inline fun ServerResponse.BodyBuilder.body(publisher: Publishe * @author Sebastien Deleuze * @since 5.2 */ -inline fun ServerResponse.BodyBuilder.bodyWithType(producer: Any): Mono = +inline fun ServerResponse.BodyBuilder.body(producer: Any): Mono = body(producer, object : ParameterizedTypeReference() {}) -/** - * Extension for [ServerResponse.BodyBuilder.body] providing a `bodyWithType(Publisher)` variant - * leveraging Kotlin reified type parameters. This extension is not subject to type - * erasure and retains actual generic type arguments. - * @param publisher the [Publisher] to write to the response - * @param the type of the elements contained in the publisher - * @author Sebastien Deleuze - * @since 5.2 - */ -inline fun ServerResponse.BodyBuilder.bodyWithType(publisher: Publisher): Mono = - body(publisher, object : ParameterizedTypeReference() {}) - /** * Coroutines variant of [ServerResponse.BodyBuilder.body] with an [Any] parameter. * @@ -97,7 +84,7 @@ suspend inline fun ServerResponse.BodyBuilder.bodyAndAwait(flo * @author Sebastien Deleuze * @since 5.0 */ -@Deprecated("Use 'sse().bodyWithType(publisher)' instead.", replaceWith = ReplaceWith("sse().bodyWithType(publisher)")) +@Deprecated("Use 'sse().body(publisher)' instead.", replaceWith = ReplaceWith("sse().body(publisher)")) inline fun ServerResponse.BodyBuilder.bodyToServerSentEvents(publisher: Publisher): Mono = contentType(MediaType.TEXT_EVENT_STREAM).body(publisher, object : ParameterizedTypeReference() {}) diff --git a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/WebClientExtensionsTests.kt b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/WebClientExtensionsTests.kt index 70dabbfde6e..bfe808c0e84 100644 --- a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/WebClientExtensionsTests.kt +++ b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/WebClientExtensionsTests.kt @@ -43,23 +43,23 @@ class WebClientExtensionsTests { @Test - fun `RequestBodySpec#bodyWithType with Publisher and reified type parameters`() { + fun `RequestBodySpec#body with Publisher and reified type parameters`() { val body = mockk>>() - requestBodySpec.bodyWithType(body) + requestBodySpec.body(body) verify { requestBodySpec.body(body, object : ParameterizedTypeReference>() {}) } } @Test fun `RequestBodySpec#body with Flow and reified type parameters`() { val body = mockk>>() - requestBodySpec.bodyWithType(body) + requestBodySpec.body(body) verify { requestBodySpec.body(ofType(), object : ParameterizedTypeReference>() {}) } } @Test fun `RequestBodySpec#body with CompletableFuture and reified type parameters`() { val body = mockk>>() - requestBodySpec.bodyWithType>(body) + requestBodySpec.body>(body) verify { requestBodySpec.body(ofType(), object : ParameterizedTypeReference>() {}) } } diff --git a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/ServerResponseExtensionsTests.kt b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/ServerResponseExtensionsTests.kt index 5d54d81e7ce..8fc3a99ce46 100644 --- a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/ServerResponseExtensionsTests.kt +++ b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/ServerResponseExtensionsTests.kt @@ -45,21 +45,21 @@ class ServerResponseExtensionsTests { @Test fun `BodyBuilder#body with Publisher and reified type parameters`() { val body = mockk>>() - bodyBuilder.bodyWithType(body) + bodyBuilder.body(body) verify { bodyBuilder.body(body, object : ParameterizedTypeReference>() {}) } } @Test fun `BodyBuilder#body with CompletableFuture and reified type parameters`() { val body = mockk>>() - bodyBuilder.bodyWithType>(body) + bodyBuilder.body>(body) verify { bodyBuilder.body(body, object : ParameterizedTypeReference>() {}) } } @Test fun `BodyBuilder#body with Flowable and reified type parameters`() { val body = mockk>>() - bodyBuilder.bodyWithType(body) + bodyBuilder.body(body) verify { bodyBuilder.body(body, object : ParameterizedTypeReference>() {}) } } diff --git a/src/docs/asciidoc/web/webflux-functional.adoc b/src/docs/asciidoc/web/webflux-functional.adoc index 17dc8450341..2cd17bb1258 100644 --- a/src/docs/asciidoc/web/webflux-functional.adoc +++ b/src/docs/asciidoc/web/webflux-functional.adoc @@ -231,8 +231,8 @@ ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).body(person, Person. [source,kotlin,role="secondary"] .Kotlin ---- -val person: Mono = ... -ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).bodyWithType(person) +val person: Person = ... +ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).bodyValue(person) ---- The following example shows how to build a 201 (CREATED) response with a `Location` header and no body: @@ -262,7 +262,7 @@ ServerResponse.ok().hint(Jackson2CodecSupport.JSON_VIEW_HINT, MyJacksonView.clas [source,kotlin,role="secondary"] .Kotlin ---- -ServerResponse.ok().hint(Jackson2CodecSupport.JSON_VIEW_HINT, MyJacksonView::class.java).bodyWithType(...) +ServerResponse.ok().hint(Jackson2CodecSupport.JSON_VIEW_HINT, MyJacksonView::class.java).body(...) ---- ==== diff --git a/src/docs/asciidoc/web/webflux-webclient.adoc b/src/docs/asciidoc/web/webflux-webclient.adoc index 44f50245c66..d53eccd8a3a 100644 --- a/src/docs/asciidoc/web/webflux-webclient.adoc +++ b/src/docs/asciidoc/web/webflux-webclient.adoc @@ -497,7 +497,7 @@ like `Mono` or Kotlin Coroutines `Deferred` as the following example shows: client.post() .uri("/persons/{id}", id) .contentType(MediaType.APPLICATION_JSON) - .bodyWithType(personDeferred) + .body(personDeferred) .retrieve() .awaitBody() ---- @@ -524,7 +524,7 @@ You can also have a stream of objects be encoded, as the following example shows client.post() .uri("/persons/{id}", id) .contentType(MediaType.APPLICATION_JSON) - .bodyWithType(people) + .body(people) .retrieve() .awaitBody() ----