tim
11/23/2021, 4:18 PM@Contextual
to de(serialize) Instant as a Long for my ktor server and I want to de(serialize) it as a Mongo Date for db operations.
I am getting the expected behaviour when updating my document, but when I insertOne
the documents instant is being serialized as a Long not a date (L22). When I later run updateOne
the instant is being correctly serialised (L28). Any idea what I'm doing wrong here?Ivan Brko
11/23/2021, 5:07 PMtim
11/24/2021, 8:43 AMcall.recieve<T>()
can (de)serialize Instant <--> EpochMilliLong. But I don't see how to specify the contextual serializer for kmongo? Perhaps the Json { ... }
configures a global singleton and so the ktor configuration block applies to both but then in that instant I would expect kmongo to serialize it as epoch milli 🤷
So how i have it working currently, is my ktor is configured as obove, I don't do anything to kmongo, and then I tag Instant as @Contextual
which results in the desired behaviourregisterSerializer
function registers a contextual serializer on the kmongo side ... so now have the desired functionality with kotlinx.datetime where ktor treats it as a string and kmongo treats it as a bson date time 🥳