Package-level declarations

Basic concepts of serial description to programmatically describe the serial form for serializers in an introspectable manner.

Types

Link copied to clipboard

Builder for SerialDescriptor for user-defined serializers.

Link copied to clipboard

Polymorphic kind represents a (bounded) polymorphic value, that is referred by some base class or interface, but its structure is defined by one of the possible implementations. Polymorphic kind is, by its definition, a union kind and is extracted to its own subtype to emphasize bounded and sealed polymorphism common property: not knowing the actual type statically and requiring formats to additionally encode it.

Link copied to clipboard
sealed class PrimitiveKind : SerialKind

Values of primitive kinds usually are represented as a single value. All default serializers for Kotlin primitives types and String have primitive kind.

Link copied to clipboard

Serial descriptor is an inherent property of KSerializer that describes the structure of the serializable type. The structure of the serializable type is not only the characteristic of the type itself, but also of the serializer as well, meaning that one type can have multiple descriptors that have completely different structures.

Link copied to clipboard
sealed class SerialKind

Serial kind is an intrinsic property of SerialDescriptor that indicates how the corresponding type is structurally represented by its serializer.

Link copied to clipboard
sealed class StructureKind : SerialKind

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

Properties

Link copied to clipboard

Retrieves KClass associated with serializer and its descriptor, if it was captured.

Link copied to clipboard

Returns an iterable of all descriptor elements.

Link copied to clipboard

Returns an iterable of all descriptor element names.

Link copied to clipboard

Returns non-nullable serial descriptor for the type if this descriptor has been auto-generated (plugin generated descriptors) or created with .nullable extension on a descriptor or serializer.

Link copied to clipboard

Returns new serial descriptor for the same type with isNullable property set to true.

Functions

Link copied to clipboard
fun buildClassSerialDescriptor(serialName: String, vararg typeParameters: SerialDescriptor, builderAction: ClassSerialDescriptorBuilder.() -> Unit = {}): SerialDescriptor

Builder for SerialDescriptor. The resulting descriptor will be uniquely identified by the given serialName, typeParameters and elements structure described in builderAction function.

Link copied to clipboard

An unsafe alternative to buildClassSerialDescriptor that supports an arbitrary SerialKind. This function is left public only for migration of pre-release users and is not intended to be used as a generally safe and stable mechanism. Beware that it can produce inconsistent or non-spec-compliant instances.

Link copied to clipboard
inline fun <T> ClassSerialDescriptorBuilder.element(elementName: String, annotations: List<Annotation> = emptyList(), isOptional: Boolean = false)

A reified version of element function that extract descriptor using serializer<T>().descriptor call with all the restrictions of serializer<T>().descriptor.

Link copied to clipboard

Looks up a descriptor of serializer registered for contextual serialization in this, using SerialDescriptor.capturedKClass as a key.

Link copied to clipboard

Retrieves a collection of descriptors which serializers are registered for polymorphic serialization in this with base class equal to descriptor's SerialDescriptor.capturedKClass. This method does not retrieve serializers registered with PolymorphicModuleBuilder.defaultDeserializer or PolymorphicModuleBuilder.defaultSerializer.

Link copied to clipboard

Creates a descriptor for the type List<T>.

Creates a descriptor for the type List<T> where T is the type associated with elementDescriptor.

Link copied to clipboard

Creates a descriptor for the type Map<K, V>.

Creates a descriptor for the type Map<K, V> where K and V are types associated with keyDescriptor and valueDescriptor respectively.

Link copied to clipboard

Factory to create trivial primitive descriptors. serialName must be non-blank and unique. Primitive descriptors should be used when the serialized form of the data has a primitive form, for example:

Link copied to clipboard

Factory to create a new descriptor that is identical to original except that the name is equal to serialName. Usually used when you want to serialize a type as another type, delegating implementation of serialize and deserialize.

Link copied to clipboard

Retrieves descriptor of type T using reified serializer function.

Retrieves descriptor of a type associated with the given KType.

Link copied to clipboard

Creates a descriptor for the type Set<T>.

Creates a descriptor for the type Set<T> where T is the type associated with elementDescriptor.