The MongoDB Kotlin driver supports contextual serializers for the kotlinx.datetime library using the @Contextual annotation from kotlinx-serialization. Since Kotlin version 2.1 these types have moved from kotlinx-datetime to the Kotlin stdlib and are thus deprecated.
// works for now, but deprecated data class SomeClass( @Contextual val someInstant: kotlinx.datetime.Instant, )
// will throw a runtime exception data class SomeClass( @Contextual val someInstant: kotlin.time.Instant, )
It would be nice to have @Contextual support for the new stdlib classes such as kotlin.date.Instant out of the box.
Workaround in the meantime: Create your custom serializer.