提交 52976246 编写于 作者: S Sebastien Deleuze

Remove bodyWithType extension from WebFlux

Since there is no more clash with the new bodyValue
method name.

Closes gh-23523
上级 14558844
......@@ -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 <reified T : Any, S : Publisher<T>> RequestBodySpec.body(publisher: S): RequestHeadersSpec<*> =
body(publisher, object : ParameterizedTypeReference<T>() {})
/**
* Extension for [WebClient.RequestBodySpec.body] providing a `bodyWithType<T>(Any)` variant
* Extension for [WebClient.RequestBodySpec.body] providing a `body(Flow<T>)` 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 <T> the type of the elements contained in the producer
* @author Sebastien Deleuze
* @since 5.2
*/
inline fun <reified T : Any> RequestBodySpec.bodyWithType(producer: Any): RequestHeadersSpec<*> =
body(producer, object : ParameterizedTypeReference<T>() {})
/**
* Extension for [WebClient.RequestBodySpec.body] providing a `bodyWithType(Publisher<T>)` 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 <T> the type of the elements contained in the publisher
* @param flow the [Flow] to write to the request
* @param <T> the type of the elements contained in the flow
* @author Sebastien Deleuze
* @since 5.2
*/
inline fun <reified T : Any> RequestBodySpec.bodyWithType(publisher: Publisher<T>): RequestHeadersSpec<*> =
body(publisher, object : ParameterizedTypeReference<T>() {})
inline fun <reified T : Any> RequestBodySpec.body(flow: Flow<T>): RequestHeadersSpec<*> =
body(flow, object : ParameterizedTypeReference<T>() {})
/**
* Extension for [WebClient.RequestBodySpec.body] providing a `bodyWithType(Flow<T>)` variant
* Extension for [WebClient.RequestBodySpec.body] providing a `body<T>(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 <T> 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 <T> the type of the elements contained in the producer
* @author Sebastien Deleuze
* @since 5.2
*/
@ExperimentalCoroutinesApi
inline fun <reified T : Any> RequestBodySpec.bodyWithType(flow: Flow<T>): RequestHeadersSpec<*> =
body(flow, object : ParameterizedTypeReference<T>() {})
inline fun <reified T : Any> RequestBodySpec.body(producer: Any): RequestHeadersSpec<*> =
body(producer, object : ParameterizedTypeReference<T>() {})
/**
* Coroutines variant of [WebClient.RequestHeadersSpec.exchange].
......
......@@ -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 <reified T : Any> ServerResponse.BodyBuilder.body(publisher: Publisher<T>): Mono<ServerResponse> =
body(publisher, object : ParameterizedTypeReference<T>() {})
/**
* Extension for [ServerResponse.BodyBuilder.body] providing a `bodyWithType<T>(Any)` variant
* Extension for [ServerResponse.BodyBuilder.body] providing a `body<T>(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 <reified T : Any> ServerResponse.BodyBuilder.body(publisher: Publishe
* @author Sebastien Deleuze
* @since 5.2
*/
inline fun <reified T : Any> ServerResponse.BodyBuilder.bodyWithType(producer: Any): Mono<ServerResponse> =
inline fun <reified T : Any> ServerResponse.BodyBuilder.body(producer: Any): Mono<ServerResponse> =
body(producer, object : ParameterizedTypeReference<T>() {})
/**
* Extension for [ServerResponse.BodyBuilder.body] providing a `bodyWithType(Publisher<T>)` 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 <T> the type of the elements contained in the publisher
* @author Sebastien Deleuze
* @since 5.2
*/
inline fun <reified T : Any> ServerResponse.BodyBuilder.bodyWithType(publisher: Publisher<T>): Mono<ServerResponse> =
body(publisher, object : ParameterizedTypeReference<T>() {})
/**
* Coroutines variant of [ServerResponse.BodyBuilder.body] with an [Any] parameter.
*
......@@ -97,7 +84,7 @@ suspend inline fun <reified T : Any> 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 <reified T : Any> ServerResponse.BodyBuilder.bodyToServerSentEvents(publisher: Publisher<T>): Mono<ServerResponse> =
contentType(MediaType.TEXT_EVENT_STREAM).body(publisher, object : ParameterizedTypeReference<T>() {})
......
......@@ -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<Publisher<List<Foo>>>()
requestBodySpec.bodyWithType(body)
requestBodySpec.body(body)
verify { requestBodySpec.body(body, object : ParameterizedTypeReference<List<Foo>>() {}) }
}
@Test
fun `RequestBodySpec#body with Flow and reified type parameters`() {
val body = mockk<Flow<List<Foo>>>()
requestBodySpec.bodyWithType(body)
requestBodySpec.body(body)
verify { requestBodySpec.body(ofType<Any>(), object : ParameterizedTypeReference<List<Foo>>() {}) }
}
@Test
fun `RequestBodySpec#body with CompletableFuture and reified type parameters`() {
val body = mockk<CompletableFuture<List<Foo>>>()
requestBodySpec.bodyWithType<List<Foo>>(body)
requestBodySpec.body<List<Foo>>(body)
verify { requestBodySpec.body(ofType<Any>(), object : ParameterizedTypeReference<List<Foo>>() {}) }
}
......
......@@ -45,21 +45,21 @@ class ServerResponseExtensionsTests {
@Test
fun `BodyBuilder#body with Publisher and reified type parameters`() {
val body = mockk<Publisher<List<Foo>>>()
bodyBuilder.bodyWithType(body)
bodyBuilder.body(body)
verify { bodyBuilder.body(body, object : ParameterizedTypeReference<List<Foo>>() {}) }
}
@Test
fun `BodyBuilder#body with CompletableFuture and reified type parameters`() {
val body = mockk<CompletableFuture<List<Foo>>>()
bodyBuilder.bodyWithType<List<Foo>>(body)
bodyBuilder.body<List<Foo>>(body)
verify { bodyBuilder.body(body, object : ParameterizedTypeReference<List<Foo>>() {}) }
}
@Test
fun `BodyBuilder#body with Flowable and reified type parameters`() {
val body = mockk<Flowable<List<Foo>>>()
bodyBuilder.bodyWithType(body)
bodyBuilder.body(body)
verify { bodyBuilder.body(body, object : ParameterizedTypeReference<List<Foo>>() {}) }
}
......
......@@ -231,8 +231,8 @@ ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).body(person, Person.
[source,kotlin,role="secondary"]
.Kotlin
----
val person: Mono<Person> = ...
ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).bodyWithType<Person>(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(...)
----
====
......
......@@ -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<Person>(personDeferred)
.body<Person>(personDeferred)
.retrieve()
.awaitBody<Unit>()
----
......@@ -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<Unit>()
----
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册