Retrofit: [Question] String[] headers in Kotlin

Created on 9 Oct 2017  路  4Comments  路  Source: square/retrofit

I'm wondering how to implement this in Kotlin

@Headers({
    "Accept: application/vnd.github.v3.full+json",
    "User-Agent: Retrofit-Sample-App"
})

Regards

Most helpful comment

Kotlin seems to understand Java arrays in annotations as varargs. (filed as possible bug: https://youtrack.jetbrains.com/issue/KT-20691)

@Headers(
    "Accept: application/vnd.github.v3.full+json",
    "User-Agent: Retrofit-Sample-App"
)

(not arrayOf)
in Kotlin will work.

All 4 comments

Does arrayOf not work?
This issue tracker works best for bugs with test cases and feature requests.
StackOverflow has people who can answer usage questions about Kotlin, Retrofit, etc.

It doesn't, it complains about requiring String but Array passed. I ended up using an interceptor to setup the headers.

Thanks

arrayOf will work. If not it's a Kotlin bug. See https://kotlinlang.org/docs/reference/annotations.html#java-annotations.

Kotlin seems to understand Java arrays in annotations as varargs. (filed as possible bug: https://youtrack.jetbrains.com/issue/KT-20691)

@Headers(
    "Accept: application/vnd.github.v3.full+json",
    "User-Agent: Retrofit-Sample-App"
)

(not arrayOf)
in Kotlin will work.

Was this page helpful?
0 / 5 - 0 ratings