zeugederunity
09/16/2020, 5:27 PMSerialName
annotation was set to retention(BINARY)
Is there any way in Kotlin 1.4.x with Serialization 1.0.0-RC to retrieve the SerialName
of an annotated property? Because reflection is now not possible anymore.Vsevolod Tolstopyatov [JB]
09/16/2020, 6:23 PMSerialDescriptor
?zeugederunity
09/16/2020, 8:38 PMinline infix fun <T : Any, TItem> KProperty1<T, TItem>.eq(value: TItem?): Bson = fieldName eq value
Usually using the default name reflection of a dataclass-property is enouth, bus due to some legacy code and naming conventions i have to use @SerialName
for some properties like @SerialName("_id") val id: Id<CompanyData>
.
In 1.3.70 i was able to retrieve the reflected name of the KProperty of a class by this:
annotations.filterIsInstance<SerialName>().singleOrNull()?.name ?: name
and then cache it.
My workaround at this point is, that i wrote a second annotation class
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.PROPERTY)
annotation class MongoDBName(val name: String)
and use this class to reflect the name. Sadly this has the sideeffect, that my properties look like this @SerialName("_id") @MongoDBName("_id") val id: Id<CompanyData>
which is quite inconvenient and harder to maintain.zeugederunity
09/16/2020, 8:42 PMzeugederunity
09/17/2020, 8:15 AM