5 changed files with 111 additions and 2 deletions
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
package org.springframework.web.reactive.function |
||||
|
||||
import org.springframework.http.ReactiveHttpInputMessage |
||||
import reactor.core.publisher.Flux |
||||
import reactor.core.publisher.Mono |
||||
import kotlin.reflect.KClass |
||||
|
||||
/** |
||||
* Extension for [BodyExtactors] providing [KClass] based API and avoiding specifying |
||||
* a class parameter when possible thanks to Kotlin reified type parameters. |
||||
* |
||||
* @since 5.0 |
||||
*/ |
||||
object BodyExtractorsExtension { |
||||
|
||||
/** |
||||
* @see BodyExtactors.toMono |
||||
*/ |
||||
inline fun <reified T : Any> toMono() : BodyExtractor<Mono<T>, ReactiveHttpInputMessage> = |
||||
BodyExtractors.toMono(T::class.java) |
||||
|
||||
/** |
||||
* @see BodyExtactors.toMono |
||||
*/ |
||||
fun <T : Any> toMono(elementClass: KClass<T>) : BodyExtractor<Mono<T>, ReactiveHttpInputMessage> = |
||||
BodyExtractors.toMono(elementClass.java) |
||||
|
||||
/** |
||||
* @see BodyExtactors.toFlux |
||||
*/ |
||||
inline fun <reified T : Any> toFlux() : BodyExtractor<Flux<T>, ReactiveHttpInputMessage> = |
||||
BodyExtractors.toFlux(T::class.java) |
||||
|
||||
/** |
||||
* @see BodyExtactors.toFlux |
||||
*/ |
||||
fun <T : Any> toFlux(elementClass: KClass<T>) : BodyExtractor<Flux<T>, ReactiveHttpInputMessage> = |
||||
BodyExtractors.toFlux(elementClass.java) |
||||
} |
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
package org.springframework.web.reactive.function |
||||
|
||||
import org.reactivestreams.Publisher |
||||
import org.springframework.http.ReactiveHttpOutputMessage |
||||
import org.springframework.http.server.reactive.ServerHttpResponse |
||||
|
||||
/** |
||||
* Extension for [BodyInserters] providing [KClass] based API and avoiding specifying |
||||
* a class parameter when possible thanks to Kotlin reified type parameters. |
||||
* |
||||
* @since 5.0 |
||||
*/ |
||||
object BodyInsertersExtension { |
||||
|
||||
/** |
||||
* @see BodyInserters.fromPublisher |
||||
*/ |
||||
inline fun <reified T : Publisher<S>, reified S : Any> fromPublisher(publisher: T) : BodyInserter<T, ReactiveHttpOutputMessage> = |
||||
BodyInserters.fromPublisher(publisher, S::class.java) |
||||
|
||||
/** |
||||
* @see BodyInserters.fromServerSentEvents |
||||
*/ |
||||
inline fun <reified T : Publisher<S>, reified S : Any> fromServerSentEvents(publisher: T) : BodyInserter<T, ServerHttpResponse> = |
||||
BodyInserters.fromServerSentEvents(publisher, S::class.java) |
||||
} |
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
package org.springframework.web.reactive.function.client |
||||
|
||||
import reactor.core.publisher.Flux |
||||
import reactor.core.publisher.Mono |
||||
import kotlin.reflect.KClass |
||||
|
||||
/** |
||||
* Extension for [ClientResponse] providing [KClass] based API. |
||||
* |
||||
* @since 5.0 |
||||
*/ |
||||
object ClientResponseExtension { |
||||
|
||||
/** |
||||
* @see ClientResponse.bodyToFlux |
||||
*/ |
||||
fun <T : Any> ClientResponse.bodyToFlux(type: KClass<T>) : Flux<T> = bodyToFlux(type.java) |
||||
|
||||
/** |
||||
* @see ClientResponse.bodyToMono |
||||
*/ |
||||
fun <T : Any> ClientResponse.bodyToMono(type: KClass<T>) : Mono<T> = bodyToMono(type.java) |
||||
} |
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
package org.springframework.web.reactive.function.server |
||||
|
||||
import kotlin.reflect.KClass |
||||
|
||||
/** |
||||
* Extension for [ServerRequest] providing [KClass] based API. |
||||
* |
||||
* @since 5.0 |
||||
*/ |
||||
object ServerRequestExtension { |
||||
|
||||
/** |
||||
* @see ServerRequest.bodyToMono |
||||
*/ |
||||
fun <T : Any> ServerRequest.bodyToMono(type: KClass<T>) = bodyToMono(type.java) |
||||
|
||||
/** |
||||
* @see ServerRequest.bodyToFlux |
||||
*/ |
||||
fun <T : Any> ServerRequest.bodyToFlux(type: KClass<T>) = bodyToFlux(type.java) |
||||
} |
Loading…
Reference in new issue