RealmSetKSerializer

class RealmSetKSerializer<E>(elementSerializer: KSerializer<E>) : KSerializer<RealmSet<E>>

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

It supports any serializable type as a type argument.

The serializer must be registered per property:

class Example : RealmObject {
@Serializable(RealmSetKSerializer::class)
var mySet: RealmSet<String> = realmSetOf()
}

or per file:

@file:UseSerializers(RealmSetKSerializer::class)

class Example : RealmObject {
var mySet: RealmSet<String> = realmSetOf()
}

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

Link copied to clipboard
constructor(elementSerializer: KSerializer<E>)

Properties

Link copied to clipboard
open override val descriptor: SerialDescriptor

Functions

Link copied to clipboard
open override fun deserialize(decoder: Decoder): RealmSet<E>
Link copied to clipboard
open override fun serialize(encoder: Encoder, value: RealmSet<E>)