-
Notifications
You must be signed in to change notification settings - Fork 619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change the retention of the attribute "SerialName" back to "RUNTIME" #1081
Comments
Seems like this framework is also affected by this binary retention (Litote/kmongo#224): |
I wonder what other annotations you need with runtime retention. E.g. |
For my use-case i only need
Talking about retention, why were they set to binary retention anyway? Edit: This |
* SerialInfo, Transient, Required: binary -> runtime * Contextual: runtime -> binary Fixes #1081
What is your use-case and why do you need this feature?
I am using the Kotlin-Serializer for a MongoDB driver (MongoDB Java Drivers + KBson and some additional features like a commons library for sharing the data classes representing the documents). The Kotlin-Serializer acts in this case as serializer for the codec-provider of the MongoDB driver. (see MongoDBExample.kt for a simplified code example)
To keep the maintainability of the queries used in the application as simple as possible, i wrote a small DSL wrapping the MongoDB Java Driver (see MongoDBExample.kt - Query DSL Example). Usually the default name reflection of the
data class
properties is enouth, but due to legacy code, changes of the datamodel, and naming conventions the names in the database and thedata class
may differ e.g.@SerialName("_id") val id: Id
. (see MongoDBExample.kt - MongoDB-naming-convention vs Kotlin-naming-convention).Hence, by retrieving the
SerialName
of theKProperty
it is possible to write this kind of queries in a very safe and low maintenance manner, given that i don't need additional property-fieldname-mapping in my code. Furthermore the approach in MongoDBExample.kt replaces the use of plain strings for the field-names in the query-definitions, lowering the code maintenance by schema-changes and the error rate by new code even more.In
Kotlin 1.3.72
withkotlinx.serialize 0.20.0
it was possible to getSerialName
attribute by reflection, providing a simple way of retrieving the name used in the database-representation (see MongoDBExample.kt - KProperty SerialName Reflection). InKotlin 1.4.10
withkotlinx.serialize 1.0.0-RC
this approach isn't possible anymore. My workaround is a second attributeMongoDBName
, redundantly keeping the information of theSerialName
attribute for the runtime reflection:This does not only increase the maintenance costs, but also increases the probability of code errors due to the fact, that one has to add two annotations with the exact same information.
Describe the solution you'd like
Change the retention of the
SerialName
annotation back toRUNTIME
, making it possible to retrieve theSerialName
at runtime.The text was updated successfully, but these errors were encountered: