Skip to content

Instantly share code, notes, and snippets.

@dsebastien
Created December 26, 2017 18:14
Show Gist options
  • Save dsebastien/82bc9b1a7158d69440312c661bbac1a7 to your computer and use it in GitHub Desktop.
Save dsebastien/82bc9b1a7158d69440312c661bbac1a7 to your computer and use it in GitHub Desktop.
Get field name
override fun getFieldName(property: KProperty1<*, *>): String {
logger.debug { "Searching for the actual Avro field name for the following property: [${property.name}]" }
var retVal: String = property.name
logger.trace { "Retrieving the Java field" }
val field: Field? = property.javaField
val avroName: AvroName?
if (field == null) {
avroName = null
logger.trace { "Java field not found. If the annotation was set, was it with @field: ?" }
} else {
logger.trace { "Java field found. Checking if the ${AvroName::class.qualifiedName} annotation is defined on it" }
avroName = field.getAnnotation(AvroName::class.java)
}
if (avroName != null) {
logger.debug { "AvroName annotation defined for the given property field: ${avroName.value}" }
retVal = avroName.value
} else {
logger.trace { "AvroName annotation not defined for the given property field. Using the default: $retVal" }
}
return retVal
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment