RealmInstantKSerializer

object RealmInstantKSerializer : KSerializer<RealmInstant>

KSerializer implementation for RealmInstant. It is serialized as a BsonDateTime, to allow direct usage on Mongodb function calls, and deserialized as an unmanaged RealmInstant.

Warning: because RealmInstant and BsonDateTime have different precision the serialization will lose precision as nanoseconds get truncated to milliseconds.

The serializer must be registered per property:

class Example : RealmObject {
@Serializable(RealmInstantKSerializer::class)
var myInstant: RealmInstant = RealmInstant.now()
}

or per file:

@file:UseSerializers(RealmInstantKSerializer::class)

class Example : RealmObject {
var myInstant: RealmInstant = RealmInstant.now()
}

Adding the following code snippet to a Kotlin file would conveniently register any field using a Realm datatype to its correspondent serializer:

@file:UseSerializers(
RealmListKSerializer::class,
RealmSetKSerializer::class,
RealmAnyKSerializer::class,
RealmInstantKSerializer::class,
MutableRealmIntKSerializer::class,
RealmUUIDKSerializer::class
)

Serializers for all Realm data types can be found in io.realm.kotlin.serializers.

Properties

Link copied to clipboard
open override val descriptor: SerialDescriptor

Functions

Link copied to clipboard
open override fun deserialize(decoder: Decoder): RealmInstant
Link copied to clipboard
open override fun serialize(encoder: Encoder, value: RealmInstant)