mercredi 3 octobre 2018

Kotlin and reflection on properties using kotlin-reflect

I am using kotlin-reflect for reflection on Kotlin data class

Definition is like this

@JsonIgnoreProperties(ignoreUnknown = true)
data class TopicConfiguration(
    @JsonProperty("max.message.bytes") var maxMessageBytes: Long? = null,
    @JsonProperty("compression.type") var compressionType: String? = null,
    @JsonProperty("retention.ms") var retentionMs: Long? = null
)

I want to get @JsonProperty using reflection, but when I try

obj
  .javaClass
  .kotlin
  .declaredMemberProperties
  .first()
  .findAnnotation<JsonProperty>()

Then I get null no matter what I try.

How do I access property annotations using reflection on Kotlin data class (namely @JsonProperty that's defined in jackson data-bind)





Aucun commentaire:

Enregistrer un commentaire