mardi 29 septembre 2020

Java annotation cannot be found per reflection on a Kotlin data class

Given this Java annotation

@Target({ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@JacksonAnnotation
public @interface JsonProperty

and this Kotlin data class

@JsonIgnoreProperties(ignoreUnknown = true)
data class LossDocument(@JsonProperty("id") val id: String)

I would expect to find the annotation either here

LossDocument::class.java.declaredFields[0].annotations

or here

LossDocument::class.java.declaredMethods.first { it.name == "getId" }

but both have zero annotations. Is this a bug? Per 53843771, my impression is this should work. I'm using Kotlin 1.4.0.





Aucun commentaire:

Enregistrer un commentaire