Quarkus/Kotlin: An annotation argument must be a compile-time constant with a java class

856 views Asked by At

In a quarkus/kotlin app, I have a rest client that is very basic:

@Path("/my/api/v1")
@RestClient
interface MyApiClient { }

Problem is, when a request fails, it returns a response that fails to be mapped. So I want to add an exception mapper, in order to log the real error:

class MyExceptionMapper : ResponseExceptionMapper<java.lang.RuntimeException?> {
    override fun toThrowable(r: Response): java.lang.RuntimeException {
        Logger.getLogger(MyApiClient::class.java).error(r.status)
        return RuntimeException("failed")
    }
}

To do so, I should annoate my client with:

@RegisterProvider(MyExceptionMapper::class.java)

Doing so, I have a kotlin error:

An annotation argument must be a compile-time constant

I googled but could find solutions only for strings. In this case, kotlin expects the java class to be a compile time constant. How to get it?

1

There are 1 answers

0
Михаил Нафталь On

Should work with simple:

@RegisterProvider(MyExceptionMapper::class)