kmongo icon indicating copy to clipboard operation
kmongo copied to clipboard

kotlinx.serialization: remove the need of reflection completely

Open zigzago opened this issue 4 years ago • 2 comments

Starting from 1.4.0, @SerialName is no longer usable with reflection at runtime. The workaround provided fro now by KMongo is to use @MongoId & @MongoProperty to detect custom @SerialName at runtime. It would be better to use an annotation processor that detects @SerialName and build a repository of ids and custom property names.

zigzago avatar Aug 18 '20 18:08 zigzago

Hi, maintainer of kotlinx.serialization here. We've changed annotation retention to binary because we were not expecting that anyone would read them via reflection (the kotlinx.serialization itself reads them via compiler plugin). We'll see if we can change retention back. I also wonder, what other annotations do you read by reflection? E.g. @Transient, @Required now also have binary retention. Can this cause problems?

sandwwraith avatar Sep 17 '20 11:09 sandwwraith

No, the issue is only with @SerialName, because KMongo needs to check the property name in order to build dedicated path for mongo queries (and also apply custom behaviour for _id fields). I see that you fixed the issue - and it's great. I let open this issue because avoiding completely reflection would be better :)

zigzago avatar Sep 21 '20 19:09 zigzago