StructureKind

Structure kind represents values with composite structure of nested elements of depth and arbitrary number. We acknowledge following structured kinds:

Regular classes

The most common case for serialization, that represents an arbitrary structure with fixed count of elements. When the regular Kotlin class is marked as Serializable, its descriptor kind will be CLASS.

Lists

LIST represent a structure with potentially unknown in advance number of elements of the same type. All standard serializable List implementors and arrays are represented as LIST kind of the same type.

Maps

MAP represent a structure with potentially unknown in advance number of key-value pairs of the same type. All standard serializable Map implementors are represented as Map kind of the same type.

Kotlin objects

A singleton object defined with object keyword with an OBJECT kind. By default, objects are serialized as empty structures without any states and their identity is preserved across serialization within the same process, so you always have the same instance of the object.

Serializers interaction

Serialization formats typically handle these kinds by marking structure start and end. E.g. the following serializable class class IntHolder(myValue: Int) of structure kind CLASS is handled by serializer as the following call sequence:

val composite = encoder.beginStructure(descriptor) // Denotes the start of the structure
composite.encodeIntElement(descriptor, index = 0, holder.myValue)
composite.endStructure(descriptor) // Denotes the end of the structure

and its corresponding Decoder counterpart.

Serial descriptor implementors note

These kinds can be used not only for collection and regular classes. For example, provided serializer for Map.Entry represents it as Map type, so it is serialized as {"actualKey": "actualValue"} map directly instead of {"key": "actualKey", "value": "actualValue"}

Inheritors

Types

Link copied to clipboard

Structure kind for regular classes with an arbitrary, but known statically, structure. Serializers typically encode classes with calls to Encoder.beginStructure and CompositeEncoder.endStructure, writing the elements of the class between these calls.

Link copied to clipboard

Structure kind for lists and arrays of an arbitrary length. Serializers typically encode classes with calls to Encoder.beginCollection and CompositeEncoder.endStructure, writing the elements of the list between these calls. Built-in list serializers treat elements as homogeneous, though application-specific serializers may impose application-specific restrictions on specific LIST types.

Link copied to clipboard

Structure kind for maps of an arbitrary length. Serializers typically encode classes with calls to Encoder.beginCollection and CompositeEncoder.endStructure, writing the elements of the map between these calls.

Link copied to clipboard

Structure kind for singleton objects defined with object keyword. By default, objects are serialized as empty structures without any state and their identity is preserved across serialization within the same process, so you always have the same instance of the object.

Functions

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open override fun toString(): String