zeugederunity

    zeugederunity

    2 years ago
    Hello everyone, after updating to Kotlin 1.4.10 with Serialization 1.0.0-RC I realized, that the 
    SerialName
     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]

    Vsevolod Tolstopyatov [JB]

    2 years ago
    Could you please file an issue and explain your use-case? Specifically, could you please elaborate on why do you want to inspect properties reflectively instead of using
    SerialDescriptor
    ?
    zeugederunity

    zeugederunity

    2 years ago
    I am using the Kotlin-Serializer for a MongoDB binding (with KBson and some additional modifications like a shared commons etc.) For improvint the writing of queries i wrote a little DSL, therefore i have functions like this:
    inline 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.
    I'll write a proper issue report tomorrow, it's it is already quite late. Thank you for the reply, good night.