Remove bodyWithType extension from WebFlux
Since there is no more clash with the new bodyValue method name. Closes gh-23523
This commit is contained in:
		
							parent
							
								
									14558844bc
								
							
						
					
					
						commit
						52976246ac
					
				|  | @ -35,13 +35,24 @@ import reactor.core.publisher.Mono | ||||||
|  * @author Sebastien Deleuze |  * @author Sebastien Deleuze | ||||||
|  * @since 5.0 |  * @since 5.0 | ||||||
|  */ |  */ | ||||||
| @Deprecated("Use 'bodyWithType' instead.", replaceWith = ReplaceWith("bodyWithType(publisher)")) |  | ||||||
| @Suppress("EXTENSION_SHADOWED_BY_MEMBER") | @Suppress("EXTENSION_SHADOWED_BY_MEMBER") | ||||||
| inline fun <reified T : Any, S : Publisher<T>> RequestBodySpec.body(publisher: S): RequestHeadersSpec<*> = | inline fun <reified T : Any, S : Publisher<T>> RequestBodySpec.body(publisher: S): RequestHeadersSpec<*> = | ||||||
| 		body(publisher, object : ParameterizedTypeReference<T>() {}) | 		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 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.body(flow: Flow<T>): RequestHeadersSpec<*> = | ||||||
|  | 		body(flow, object : ParameterizedTypeReference<T>() {}) | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Extension for [WebClient.RequestBodySpec.body] providing a `body<T>(Any)` variant | ||||||
|  * leveraging Kotlin reified type parameters. This extension is not subject to type |  * leveraging Kotlin reified type parameters. This extension is not subject to type | ||||||
|  * erasure and retains actual generic type arguments. |  * erasure and retains actual generic type arguments. | ||||||
|  * @param producer the producer to write to the request. This must be a |  * @param producer the producer to write to the request. This must be a | ||||||
|  | @ -51,34 +62,9 @@ inline fun <reified T : Any, S : Publisher<T>> RequestBodySpec.body(publisher: S | ||||||
|  * @author Sebastien Deleuze |  * @author Sebastien Deleuze | ||||||
|  * @since 5.2 |  * @since 5.2 | ||||||
|  */ |  */ | ||||||
| inline fun <reified T : Any> RequestBodySpec.bodyWithType(producer: Any): RequestHeadersSpec<*> = | inline fun <reified T : Any> RequestBodySpec.body(producer: Any): RequestHeadersSpec<*> = | ||||||
| 		body(producer, object : ParameterizedTypeReference<T>() {}) | 		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 |  | ||||||
|  * @author Sebastien Deleuze |  | ||||||
|  * @since 5.2 |  | ||||||
|  */ |  | ||||||
| inline fun <reified T : Any> RequestBodySpec.bodyWithType(publisher: Publisher<T>): RequestHeadersSpec<*> = |  | ||||||
| 		body(publisher, object : ParameterizedTypeReference<T>() {}) |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * Extension for [WebClient.RequestBodySpec.body] providing a `bodyWithType(Flow<T>)` 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 |  | ||||||
|  * @author Sebastien Deleuze |  | ||||||
|  * @since 5.2 |  | ||||||
|  */ |  | ||||||
| @ExperimentalCoroutinesApi |  | ||||||
| inline fun <reified T : Any> RequestBodySpec.bodyWithType(flow: Flow<T>): RequestHeadersSpec<*> = |  | ||||||
| 		body(flow, object : ParameterizedTypeReference<T>() {}) |  | ||||||
| 
 |  | ||||||
| /** | /** | ||||||
|  * Coroutines variant of [WebClient.RequestHeadersSpec.exchange]. |  * Coroutines variant of [WebClient.RequestHeadersSpec.exchange]. | ||||||
|  * |  * | ||||||
|  |  | ||||||
|  | @ -32,13 +32,12 @@ import reactor.core.publisher.Mono | ||||||
|  * @author Sebastien Deleuze |  * @author Sebastien Deleuze | ||||||
|  * @since 5.0 |  * @since 5.0 | ||||||
|  */ |  */ | ||||||
| @Deprecated("Use 'bodyWithType' instead.", replaceWith = ReplaceWith("bodyWithType(publisher)")) |  | ||||||
| @Suppress("EXTENSION_SHADOWED_BY_MEMBER") | @Suppress("EXTENSION_SHADOWED_BY_MEMBER") | ||||||
| inline fun <reified T : Any> ServerResponse.BodyBuilder.body(publisher: Publisher<T>): Mono<ServerResponse> = | inline fun <reified T : Any> ServerResponse.BodyBuilder.body(publisher: Publisher<T>): Mono<ServerResponse> = | ||||||
| 		body(publisher, object : ParameterizedTypeReference<T>() {}) | 		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 |  * leveraging Kotlin reified type parameters. This extension is not subject to type | ||||||
|  * erasure and retains actual generic type arguments. |  * erasure and retains actual generic type arguments. | ||||||
|  * @param producer the producer to write to the response. This must be a |  * @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 |  * @author Sebastien Deleuze | ||||||
|  * @since 5.2 |  * @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>() {}) | 		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. |  * 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 |  * @author Sebastien Deleuze | ||||||
|  * @since 5.0 |  * @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> = | inline fun <reified T : Any> ServerResponse.BodyBuilder.bodyToServerSentEvents(publisher: Publisher<T>): Mono<ServerResponse> = | ||||||
| 		contentType(MediaType.TEXT_EVENT_STREAM).body(publisher, object : ParameterizedTypeReference<T>() {}) | 		contentType(MediaType.TEXT_EVENT_STREAM).body(publisher, object : ParameterizedTypeReference<T>() {}) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -43,23 +43,23 @@ class WebClientExtensionsTests { | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 	@Test | 	@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>>>() | 		val body = mockk<Publisher<List<Foo>>>() | ||||||
| 		requestBodySpec.bodyWithType(body) | 		requestBodySpec.body(body) | ||||||
| 		verify { requestBodySpec.body(body, object : ParameterizedTypeReference<List<Foo>>() {}) } | 		verify { requestBodySpec.body(body, object : ParameterizedTypeReference<List<Foo>>() {}) } | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Test | 	@Test | ||||||
| 	fun `RequestBodySpec#body with Flow and reified type parameters`() { | 	fun `RequestBodySpec#body with Flow and reified type parameters`() { | ||||||
| 		val body = mockk<Flow<List<Foo>>>() | 		val body = mockk<Flow<List<Foo>>>() | ||||||
| 		requestBodySpec.bodyWithType(body) | 		requestBodySpec.body(body) | ||||||
| 		verify { requestBodySpec.body(ofType<Any>(), object : ParameterizedTypeReference<List<Foo>>() {}) } | 		verify { requestBodySpec.body(ofType<Any>(), object : ParameterizedTypeReference<List<Foo>>() {}) } | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Test | 	@Test | ||||||
| 	fun `RequestBodySpec#body with CompletableFuture and reified type parameters`() { | 	fun `RequestBodySpec#body with CompletableFuture and reified type parameters`() { | ||||||
| 		val body = mockk<CompletableFuture<List<Foo>>>() | 		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>>() {}) } | 		verify { requestBodySpec.body(ofType<Any>(), object : ParameterizedTypeReference<List<Foo>>() {}) } | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -45,21 +45,21 @@ class ServerResponseExtensionsTests { | ||||||
| 	@Test | 	@Test | ||||||
| 	fun `BodyBuilder#body with Publisher and reified type parameters`() { | 	fun `BodyBuilder#body with Publisher and reified type parameters`() { | ||||||
| 		val body = mockk<Publisher<List<Foo>>>() | 		val body = mockk<Publisher<List<Foo>>>() | ||||||
| 		bodyBuilder.bodyWithType(body) | 		bodyBuilder.body(body) | ||||||
| 		verify { bodyBuilder.body(body, object : ParameterizedTypeReference<List<Foo>>() {}) } | 		verify { bodyBuilder.body(body, object : ParameterizedTypeReference<List<Foo>>() {}) } | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Test | 	@Test | ||||||
| 	fun `BodyBuilder#body with CompletableFuture and reified type parameters`() { | 	fun `BodyBuilder#body with CompletableFuture and reified type parameters`() { | ||||||
| 		val body = mockk<CompletableFuture<List<Foo>>>() | 		val body = mockk<CompletableFuture<List<Foo>>>() | ||||||
| 		bodyBuilder.bodyWithType<List<Foo>>(body) | 		bodyBuilder.body<List<Foo>>(body) | ||||||
| 		verify { bodyBuilder.body(body, object : ParameterizedTypeReference<List<Foo>>() {}) } | 		verify { bodyBuilder.body(body, object : ParameterizedTypeReference<List<Foo>>() {}) } | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Test | 	@Test | ||||||
| 	fun `BodyBuilder#body with Flowable and reified type parameters`() { | 	fun `BodyBuilder#body with Flowable and reified type parameters`() { | ||||||
| 		val body = mockk<Flowable<List<Foo>>>() | 		val body = mockk<Flowable<List<Foo>>>() | ||||||
| 		bodyBuilder.bodyWithType(body) | 		bodyBuilder.body(body) | ||||||
| 		verify { bodyBuilder.body(body, object : ParameterizedTypeReference<List<Foo>>() {}) } | 		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"] | [source,kotlin,role="secondary"] | ||||||
| .Kotlin | .Kotlin | ||||||
| ---- | ---- | ||||||
| val person: Mono<Person> = ... | val person: Person = ... | ||||||
| ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).bodyWithType<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: | 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"] | [source,kotlin,role="secondary"] | ||||||
| .Kotlin | .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() | 	client.post() | ||||||
| 			.uri("/persons/{id}", id) | 			.uri("/persons/{id}", id) | ||||||
| 			.contentType(MediaType.APPLICATION_JSON) | 			.contentType(MediaType.APPLICATION_JSON) | ||||||
| 			.bodyWithType<Person>(personDeferred) | 			.body<Person>(personDeferred) | ||||||
| 			.retrieve() | 			.retrieve() | ||||||
| 			.awaitBody<Unit>() | 			.awaitBody<Unit>() | ||||||
| ---- | ---- | ||||||
|  | @ -524,7 +524,7 @@ You can also have a stream of objects be encoded, as the following example shows | ||||||
| 	client.post() | 	client.post() | ||||||
| 			.uri("/persons/{id}", id) | 			.uri("/persons/{id}", id) | ||||||
| 			.contentType(MediaType.APPLICATION_JSON) | 			.contentType(MediaType.APPLICATION_JSON) | ||||||
| 			.bodyWithType(people) | 			.body(people) | ||||||
| 			.retrieve() | 			.retrieve() | ||||||
| 			.awaitBody<Unit>() | 			.awaitBody<Unit>() | ||||||
| ---- | ---- | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue