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 a default parameters constraint.
Example of optionality:
@Serializable
class Holder(
val a: Int, // isElementOptional(0) == false
val b: Int?, // isElementOptional(1) == false
val c: Int? = null, // isElementOptional(2) == true
val d: List<Int>, // isElementOptional(3) == false
val e: List<Int> = listOf(1), // isElementOptional(4) == true
)
Content copied to clipboard
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).