Builder for SerialDescriptor for user-defined serializers.

Both explicit builder functions and implicit (using reified type-parameters) are present and are equivalent. For example, element<Int?>("nullableIntField") is indistinguishable from element("nullableIntField", IntSerializer.descriptor.nullable) and from element("nullableIntField", descriptor<Int?>).

Please refer to SerialDescriptor builder function for a complete example.


Link copied to clipboard
Link copied to clipboard


Link copied to clipboard
fun element(elementName: String, descriptor: SerialDescriptor, annotations: List<Annotation> = emptyList(), isOptional: Boolean = false)

Add an element with a given name, descriptor, type annotations and optionality the resulting descriptor.

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.