elementsCount
The number of elements this descriptor describes, besides from the class itself. elementsCount describes the number of semantic elements, not the number of actual fields/properties in the serialized form, even though they frequently match.
For example, for the following class class Complex(val real: Long, val imaginary: Long)
the corresponding descriptor and the serialized form both have two elements, while for List<Int>
the corresponding descriptor has a single element (IntDescriptor
, the type of list element), but from zero up to Int.MAX_VALUE
values in the serialized form:
@Serializable
class Complex(val real: Long, val imaginary: Long)
Complex.serializer().descriptor.elementsCount // Returns 2
@Serializable
class OuterList(val list: List<Int>)
OuterList.serializer().descriptor.getElementDescriptor(0).elementsCount // Returns 1
Content copied to clipboard