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 90595810f5..4f68d89184 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 @@ -17,6 +17,10 @@ package org.springframework.web.reactive.function.client import org.reactivestreams.Publisher +import org.springframework.http.ResponseEntity +import reactor.core.publisher.Flux +import reactor.core.publisher.Mono +import kotlin.reflect.KClass /** * Extension for [WebClient.RequestBodySpec.body] providing a variant without explicit class @@ -25,5 +29,71 @@ import org.reactivestreams.Publisher * @author Sebastien Deleuze * @since 5.0 */ +@Suppress("EXTENSION_SHADOWED_BY_MEMBER") inline fun > WebClient.RequestBodySpec.body(publisher: S): WebClient.RequestHeadersSpec<*> = body(publisher, T::class.java) + +/** + * Extension for [WebClient.ResponseSpec.bodyToMono] providing a [KClass] based variant. + * + * @author Sebastien Deleuze + * @since 5.0 + */ +fun WebClient.ResponseSpec.bodyToMono(type: KClass): Mono = bodyToMono(type.java) + +/** + * Extension for [WebClient.ResponseSpec.bodyToMono] providing a `bodyToMono()` variant. + * + * @author Sebastien Deleuze + * @since 5.0 + */ +inline fun WebClient.ResponseSpec.bodyToMono(): Mono = bodyToMono(T::class.java) + + +/** + * Extension for [WebClient.ResponseSpec.bodyToFlux] providing a [KClass] based variant. + * + * @author Sebastien Deleuze + * @since 5.0 + */ +fun WebClient.ResponseSpec.bodyToFlux(type: KClass): Flux = bodyToFlux(type.java) + +/** + * Extension for [WebClient.ResponseSpec.bodyToFlux] providing a `bodyToFlux()` variant. + * + * @author Sebastien Deleuze + * @since 5.0 + */ +inline fun WebClient.ResponseSpec.bodyToFlux(): Flux = bodyToFlux(T::class.java) + +/** + * Extension for [WebClient.ResponseSpec.bodyToEntity] providing a [KClass] based variant. + * + * @author Sebastien Deleuze + * @since 5.0 + */ +fun WebClient.ResponseSpec.bodyToEntity(type: KClass): Mono> = bodyToEntity(type.java) + +/** + * Extension for [WebClient.ResponseSpec.bodyToEntity] providing a `bodyToEntity()` variant. + * + * @author Sebastien Deleuze + * @since 5.0 + */ +inline fun WebClient.ResponseSpec.bodyToEntity(): Mono> = bodyToEntity(T::class.java) + +/** + * Extension for [WebClient.ResponseSpec.bodyToEntityList] providing a [KClass] based variant. + * + * @author Sebastien Deleuze + * @since 5.0 + */ +fun WebClient.ResponseSpec.bodyToEntityList(type: KClass): Mono>> = bodyToEntityList(type.java) + +/** + * Extension for [WebClient.ResponseSpec.bodyToEntityList] providing a `bodyToEntityList()` variant. + * + * @author Sebastien Deleuze + * @since 5.0 + */ +inline fun WebClient.ResponseSpec.bodyToEntityList(): Mono>> = bodyToEntityList(T::class.java)