Ok, found out that Jackson annotation was attached to Java field, not Kotlin property. So this workaround works:
println(C::class.memberProperties.first().javaField!!.declaredAnnotations.get(0).annotationClass)
Output: class com.fasterxml.jackson.annotation.JsonProperty
UPD:
And if data class is used then this:
import kotlin.reflect.full.primaryConstructor
data class C (
@com.fasterxml.jackson.annotation.JsonProperty
var x: Int = 0
)
val prop = C::x
println(C::class.primaryConstructor
?.parameters
?.find { it.name == prop.name }
?.annotations
?.first()
?.annotationClass
)
Output: class com.fasterxml.jackson.annotation.JsonProperty
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…