RealmDictionaryKSerializer

class RealmDictionaryKSerializer<E>(elementSerializer: <ERROR CLASS><E>)

KSerializer implementation for RealmDictionary. Serialization is done as a generic map structure, whilst deserialization is done into an unmanaged RealmDictionary.

It supports any serializable type as a type argument.

The serializer must be registered per property:

class Example : RealmObject {
@Serializable(RealmDictionaryKSerializer::class)
var myDictionary: RealmDictionary<String> = realmDictionaryOf()
}

or per file:

@file:UseSerializers(RealmDictionaryKSerializer::class)

class Example : RealmObject {
var myDictionary: RealmDictionary<String> = realmDictionaryOf()
}

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.

Constructors

RealmDictionaryKSerializer
Link copied to clipboard
fun <E> RealmDictionaryKSerializer(elementSerializer: <ERROR CLASS><E>)

Functions

deserialize
Link copied to clipboard
open fun deserialize(decoder: <ERROR CLASS>): RealmDictionary<E>
serialize
Link copied to clipboard
open fun serialize(encoder: <ERROR CLASS>, value: RealmDictionary<E>)

Properties

descriptor
Link copied to clipboard
open val descriptor: <ERROR CLASS>