https://kotlinlang.org logo
#micronaut
Title
# micronaut
r

reik.schatz

09/04/2019, 3:19 PM
does anyone have an example of a custom
TokenValidator
in kotlin? struggling a bit with
Type mismatch, Type inference failed
for
Flowable
and
Publisher
s

Shawn A

09/04/2019, 3:23 PM
An example of your current code would be helpful.
r

reik.schatz

09/04/2019, 3:26 PM
sure hang on 🙂
so I have this
class BouncerAuthentication: Authentication
and
Copy code
@Singleton
@Requires(notEnv = [ Environment.TEST ])
@Replaces(JwtTokenValidator::class)
class BouncerTokenValidator(): TokenValidator {
    private val logger = KotlinLogging.logger {}

    override fun validateToken(token: String?): Publisher<Authentication> {
        return if (token != null) {
            try {
                Flowable.just(BouncerAuthentication())
            } catch (e: BouncerAccountFacadeException) {
                logger.error(e) { "Exception using authgateway" }
                Flowable.empty()
            }
        } else {
            logger.trace { "Token is missing" }
            Flowable.empty()
        }
    }
}
BouncerTokenValidator.kt: (24, 13): Type mismatch: inferred type is Flowable<BouncerAuthentication!> but Publisher<Authentication> was expected
BouncerTokenValidator.kt: (28, 26): Type inference failed: Not enough information to infer parameter T in fun <T : Any!> empty(): Flowable<T!>!
I get it to compile with a lot of verbosity, i.e. changing to
Flowable.empty<Authentication>()
s

Shawn A

09/04/2019, 3:51 PM
It might be worth asking in the #general channel as it seems general enough.
45 Views