Created
December 26, 2017 18:14
-
-
Save dsebastien/82bc9b1a7158d69440312c661bbac1a7 to your computer and use it in GitHub Desktop.
Get field name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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