isElementOptional

Whether the element at the given index is optional (can be absent in serialized form). For generated descriptors, all elements that have a corresponding default parameter value are marked as optional. Custom serializers can treat optional values in a serialization-specific manner without default parameters constraint.

Example of optionality:

@Serializable
class Holder(
val a: Int, // Optional == false
val b: Int?, // Optional == false
val c: Int? = null, // Optional == true
val d: List<Int>, // Optional == false
val e: List<Int> = listOf(1), // Optional == true
)

Returns false for valid indices of collections, maps and enums.

Throws

for an illegal index values.

if the current descriptor does not support children elements (e.g. is a primitive).