10/16/2020, 5:58 PM
Hey, I'm using
in Ktor. How would I serialize the ObjectId class to the String type in my class.
kotlinx.serialization.SerializationException: Class 'WrappedObjectId' is not registered for polymorphic serialization in the scope of 'Id'.
Mark the base class as 'sealed' or register the serializer explicitly.
This is what I get 😞 My model class:
Forgot to mention that it works for document to object mapping fine, but only when sending the same object as a response to an API call, it doesn't work. Managed to make it work using this in Ktor:
val jsonConfig = Json { serializersModule = IdKotlinXSerializationModule }
    install(ContentNegotiation) { json(jsonConfig) }
using dependency:
Only problem now: the
field is still returned as
instead of
even while using the
annotation 😫
Also, how do I represent other types? E.g. The
class for geo-spatial queries?
readString can only be called when CurrentBSONType is STRING, not when CurrentBSONType is DOCUMENT.
I get this error when I use this custom serializer: