EmptyListSerializer

class EmptyListSerializer<T>(elementSerializer: KSerializer<T>) : KSerializer<List<T>>

A custom serializer for handling nullable lists during serialization and deserialization.

This serializer ensures that null values are deserialized as an empty list (List<T>), avoiding potential issues with nullability when working with collections. It can be used for fields that are expected to be lists but may sometimes be null in the input.

Parameters

T

The type of elements contained within the list.

Constructors

Link copied to clipboard
constructor(elementSerializer: KSerializer<T>)

Properties

Link copied to clipboard
open override val descriptor: SerialDescriptor

The serial descriptor for the list, derived from the element serializer.

Functions

Link copied to clipboard
open override fun deserialize(decoder: Decoder): List<T>

Deserializes a nullable list into a non-nullable list. If the input is null, it returns an empty list instead.

Link copied to clipboard
open override fun serialize(encoder: Encoder, value: List<T>)

Serializes a list of type T into the desired output format.