Remove object wrappers in Kotlin extensions
This commit also improve significantly Kotlin extensions documentation. Issue: SPR-15127
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
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.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @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,42 @@
|
||||
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
|
||||
|
||||
/**
|
||||
* Function for providing a `toMono()` alternative to `BodyExtractors.toMono(Foo::class.java)`.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
inline fun <reified T : Any> toMono() : BodyExtractor<Mono<T>, ReactiveHttpInputMessage> =
|
||||
BodyExtractors.toMono(T::class.java)
|
||||
|
||||
/**
|
||||
* Function for providing a `toMono(Foo::class)` alternative to `BodyExtractors.toMono(Foo::class.java)`.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> toMono(elementClass: KClass<T>) : BodyExtractor<Mono<T>, ReactiveHttpInputMessage> =
|
||||
BodyExtractors.toMono(elementClass.java)
|
||||
|
||||
/**
|
||||
* Function for providing a `toFlux()` alternative to `BodyExtractors.toFlux(Foo::class.java)`.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
inline fun <reified T : Any> toFlux() : BodyExtractor<Flux<T>, ReactiveHttpInputMessage> =
|
||||
BodyExtractors.toFlux(T::class.java)
|
||||
|
||||
/**
|
||||
* Function for providing a `toFlux(Foo::class)` alternative to `BodyExtractors.toFlux(Foo::class.java)`.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> toFlux(elementClass: KClass<T>) : BodyExtractor<Flux<T>, ReactiveHttpInputMessage> =
|
||||
BodyExtractors.toFlux(elementClass.java)
|
||||
@@ -1,27 +0,0 @@
|
||||
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.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @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 @@
|
||||
package org.springframework.web.reactive.function
|
||||
|
||||
import org.reactivestreams.Publisher
|
||||
import org.springframework.http.ReactiveHttpOutputMessage
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse
|
||||
|
||||
/**
|
||||
* Function for providing a `fromPublisher(publisher)` alternative to `BodyInserters.fromPublisher(publisher, Foo::class.java)`.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
inline fun <reified T : Publisher<S>, reified S : Any> fromPublisher(publisher: T) : BodyInserter<T, ReactiveHttpOutputMessage> =
|
||||
BodyInserters.fromPublisher(publisher, S::class.java)
|
||||
|
||||
/**
|
||||
* Function for providing a `fromServerSentEvents(publisher)` alternative to `BodyInserters.fromServerSentEvents(publisher, Foo::class.java)`.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
inline fun <reified T : Publisher<S>, reified S : Any> fromServerSentEvents(publisher: T) : BodyInserter<T, ServerHttpResponse> =
|
||||
BodyInserters.fromServerSentEvents(publisher, S::class.java)
|
||||
@@ -1,24 +0,0 @@
|
||||
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.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @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,24 @@
|
||||
package org.springframework.web.reactive.function.client
|
||||
|
||||
import reactor.core.publisher.Flux
|
||||
import reactor.core.publisher.Mono
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
|
||||
/**
|
||||
* Extension for [ClientResponse.bodyToMono] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> ClientResponse.bodyToMono(type: KClass<T>) : Mono<T> = bodyToMono(type.java)
|
||||
|
||||
/**
|
||||
* Extension for [ClientResponse.bodyToFlux] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> ClientResponse.bodyToFlux(type: KClass<T>) : Flux<T> = bodyToFlux(type.java)
|
||||
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package org.springframework.web.reactive.function.server
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
/**
|
||||
* Extension for [ServerRequest] providing [KClass] based API.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @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)
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.springframework.web.reactive.function.server
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
|
||||
/**
|
||||
* Extension for [ServerRequest.bodyToMono] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> ServerRequest.bodyToMono(type: KClass<T>) = bodyToMono(type.java)
|
||||
|
||||
/**
|
||||
* Extension for [ServerRequest.bodyToFlux] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> ServerRequest.bodyToFlux(type: KClass<T>) = bodyToFlux(type.java)
|
||||
Reference in New Issue
Block a user