Package-level declarations
Basic concepts of serial description to programmatically describe the serial form for serializers in an introspectable manner.
Types
Builder for SerialDescriptor for user-defined serializers.
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.
Values of primitive kinds usually are represented as a single value. All default serializers for Kotlin primitives types and String have primitive kind.
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 structure.
Serial kind is an intrinsic property of SerialDescriptor that indicates how the corresponding type is structurally represented by its serializer.
Structure kind represents values with composite structure of nested elements of depth and arbitrary number. We acknowledge following structured kinds:
Properties
Retrieves KClass associated with serializer and its descriptor, if it was captured.
Returns an iterable of all descriptor elements.
Returns an iterable of all descriptor element names.
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.
Returns new serial descriptor for the same type with isNullable property set to true
.
Functions
Builder for SerialDescriptor. The resulting descriptor will be uniquely identified by the given serialName, typeParameters and elements structure described in builderAction function.
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 generally-safe and stable mechanism. Beware that it can produce inconsistent or non spec-compliant instances.
A reified version of element function that extract descriptor using serializer<T>().descriptor
call with all the restrictions of serializer<T>().descriptor
.
Looks up a descriptor of serializer registered for contextual serialization in this, using SerialDescriptor.capturedKClass as a key.
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.
Creates a descriptor for the type List<T>
.
Creates a descriptor for the type List<T>
where T
is the type associated with elementDescriptor.
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.
Factory to create a trivial primitive descriptors. Primitive descriptors should be used when the serialized form of the data has a primitive form, for example:
Factory to create a new descriptor that is identical to original except that the name is equal to serialName. Should be used when you want to serialize a type as another non-primitive type. Don't use this if you want to serialize a type as a primitive value, use PrimitiveSerialDescriptor instead.
Retrieves descriptor of type T using reified serializer function.
Retrieves descriptor of type associated with the given KType
Creates a descriptor for the type Set<T>
.
Creates a descriptor for the type Set<T>
where T
is the type associated with elementDescriptor.