DeserializationStrategy

interface DeserializationStrategy<T>

Deserialization strategy defines the serial form of a type T, including its structural description, declared by the descriptor and the actual deserialization process, defined by the implementation of the deserialize method.

deserialize method takes an instance of Decoder, and, knowing the serial form of the T, invokes primitive retrieval methods on the decoder and then transforms the received primitives to an instance of T.

A serial form of the type is a transformation of the concrete instance into a sequence of primitive values and vice versa. The serial form is not required to completely mimic the structure of the class, for example, a specific implementation may represent multiple integer values as a single string, omit or add some values that are present in the type, but not in the instance.

For a more detailed explanation of the serialization process, please refer to KSerializer documentation.

Functions

Link copied to clipboard
abstract fun deserialize(decoder: Decoder): T

Deserializes the value of type T using the format that is represented by the given decoder. deserialize method is format-agnostic and operates with a high-level structured Decoder API. As long as most of the formats imply an arbitrary order of properties, deserializer should be able to decode these properties in an arbitrary order and in a format-agnostic way. For that purposes, CompositeDecoder.decodeElementIndex-based loop is used: decoder firstly signals property at which index it is ready to decode and then expects caller to decode property with the given index.

Properties

Link copied to clipboard
abstract val descriptor: SerialDescriptor

Describes the structure of the serializable representation of T, that current deserializer is able to deserialize.

Inheritors

Link copied to clipboard