Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin + Spring AliasFor

I've been trying to use Springs @AliasFor annotation in a Kotlin project but it seems that the annotation on the annotation parameter isn't visible at runtime (hence it's not picked up by Spring).

For example:

@RequestMapping(method = arrayOf(RequestMethod.POST))
annotation class PostMapping(
    @get:AliasFor(annotation = RequestMapping::class, attribute = "value")
    vararg val value: String = arrayOf())

And...

// Returns empty array instead of array with the @AliasFor annotation
PostMapping::class.java.methods[0].annotations

Is there something I'm missing?

like image 904
Arthur Avatar asked Feb 07 '23 07:02

Arthur


2 Answers

That's a bug in Kotlin, which is not fixed at the moment: KT-11475.

like image 124
Michael Avatar answered Feb 09 '23 19:02

Michael


Issue seems to has been fixed within scope of KT-25287 i.e. snippet from question should work for Kotlin 1.3+.

like image 29
Pazkooda Avatar answered Feb 09 '23 20:02

Pazkooda