CanonicalSetSerializer

class CanonicalSetSerializer<E>(eSerializer: KSerializer<E>) : KSerializer<Set<E>>

KSerializer for a Set that emits elements in element order, so that — subject to the precondition below — two replicas at the same logical state produce identical bytes regardless of merge order.

GSet.piece is elements + other.elements, which yields a LinkedHashSet in merge order — so the auto-generated serializer encoded the same logical set differently depending on which side of the join a replica saw first (issue #1957).

Wire format: a list, matching DotSetSerializerListSerializer preserves the sorted order and every format encodes a list as an array.

Sort order, and its total-preorder caveat, are as described on CanonicalMapSerializer.

Precondition — this class canonicalises the element ORDER, nothing else. The bytes are canonical only if E itself serializes canonically: an E that reaches an unordered Set or Map field through a non-canonical serializer makes the whole encoding non-canonical, however this class orders the elements around it.

E may be @Contextual or polymorphic, on the same terms as CanonicalMapSerializer's key (#2035).

Constructors

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

Properties

Link copied to clipboard
open override val descriptor: SerialDescriptor

Functions

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