Hey, I'm using `org.litote.kmongo:kmongo-coroutine...
# kmongo
m
Hey, I'm using
org.litote.kmongo:kmongo-coroutine-serialization:4.1.3
in Ktor. How would I serialize the ObjectId class to the String type in my class.
Copy code
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:
Copy code
val jsonConfig = Json { serializersModule = IdKotlinXSerializationModule }
    install(ContentNegotiation) { json(jsonConfig) }
using dependency:
implementation("org.litote.kmongo:kmongo-id-serialization:4.1.3")
Only problem now: the
_id
field is still returned as
_id
instead of
id
even while using the
@SerialName("_id")
annotation 😫
Also, how do I represent other types? E.g. The
Point
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:
101 Views