Browse Source

Add bodyToMono/Flux<Foo>() Kotlin extensions

Issue: SPR-15128
pull/1286/head
Sebastien Deleuze 9 years ago
parent
commit
b04b41b93b
  1. 18
      spring-web-reactive/src/main/kotlin/org/springframework/web/reactive/function/client/ClientResponseExtensions.kt
  2. 16
      spring-web-reactive/src/main/kotlin/org/springframework/web/reactive/function/server/ServerRequestExtensions.kt

18
spring-web-reactive/src/main/kotlin/org/springframework/web/reactive/function/client/ClientResponseExtensions.kt

@ -13,6 +13,15 @@ import kotlin.reflect.KClass @@ -13,6 +13,15 @@ import kotlin.reflect.KClass
*/
fun <T : Any> ClientResponse.bodyToMono(type: KClass<T>) : Mono<T> = bodyToMono(type.java)
/**
* Extension for [ClientResponse.bodyToMono] providing a `bodyToMono<Foo>()` variant.
*
* @author Sebastien Deleuze
* @since 5.0
*/
inline fun <reified T : Any> ClientResponse.bodyToMono() = bodyToMono(T::class.java)
/**
* Extension for [ClientResponse.bodyToFlux] providing a [KClass] based variant.
*
@ -21,4 +30,13 @@ fun <T : Any> ClientResponse.bodyToMono(type: KClass<T>) : Mono<T> = bodyToMono( @@ -21,4 +30,13 @@ fun <T : Any> ClientResponse.bodyToMono(type: KClass<T>) : Mono<T> = bodyToMono(
*/
fun <T : Any> ClientResponse.bodyToFlux(type: KClass<T>) : Flux<T> = bodyToFlux(type.java)
/**
* Extension for [ClientResponse.bodyToFlux] providing a `bodyToFlux<Foo>()` variant.
*
* @author Sebastien Deleuze
* @since 5.0
*/
inline fun <reified T : Any> ClientResponse.bodyToFlux() = bodyToFlux(T::class.java)

16
spring-web-reactive/src/main/kotlin/org/springframework/web/reactive/function/server/ServerRequestExtensions.kt

@ -11,6 +11,14 @@ import kotlin.reflect.KClass @@ -11,6 +11,14 @@ import kotlin.reflect.KClass
*/
fun <T : Any> ServerRequest.bodyToMono(type: KClass<T>) = bodyToMono(type.java)
/**
* Extension for [ServerRequest.bodyToMono] providing a `bodyToMono<Foo>()` variant.
*
* @author Sebastien Deleuze
* @since 5.0
*/
inline fun <reified T : Any> ServerRequest.bodyToMono() = bodyToMono(T::class.java)
/**
* Extension for [ServerRequest.bodyToFlux] providing a [KClass] based variant.
*
@ -18,3 +26,11 @@ fun <T : Any> ServerRequest.bodyToMono(type: KClass<T>) = bodyToMono(type.java) @@ -18,3 +26,11 @@ fun <T : Any> ServerRequest.bodyToMono(type: KClass<T>) = bodyToMono(type.java)
* @since 5.0
*/
fun <T : Any> ServerRequest.bodyToFlux(type: KClass<T>) = bodyToFlux(type.java)
/**
* Extension for [ServerRequest.bodyToFlux] providing a `bodyToFlux<Foo>()` variant.
*
* @author Sebastien Deleuze
* @since 5.0
*/
inline fun <reified T : Any> ServerRequest.bodyToFlux() = bodyToFlux(T::class.java)

Loading…
Cancel
Save