OptionalBoolean

Represents a value that encapsulate the optional and value state of a Boolean in the Discord API. Specifically:

  • Missing - a Boolean field that was not present in the serialized entity.

  • Value - a Boolean field that was assigned a non-null value in the serialized entity.

Note that there is no nullable variant present. Use Boolean? or OptionalBoolean? for this case instead.

These classes are fully (de)serializable with kotlinx.serialization.

Note that kotlinx.serialization does not call serializers for values that are not present in the serialized format. Optional fields should have a default value of OptionalBoolean.Missing:

@Serializable
class DiscordUser(
val id: Boolean,
val username: String,
val bot: OptionalBoolean = OptionalBoolean.Missing
)

Inheritors

Types

Link copied to clipboard

Represents a Boolean field that was not present in the serialized entity.

Link copied to clipboard
class Value(val value: Boolean) : OptionalBoolean

Represents a field that was assigned a non-null value in the serialized entity. Equality and hashcode is implemented through its value.

Properties

Link copied to clipboard
Link copied to clipboard

returns null if this is null, calls OptionalBoolean.asNullable otherwise.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

returns null if this is null or OptionalBoolean.Missing, calls OptionalBoolean.Value.value otherwise.

Functions

Link copied to clipboard
operator fun not(): OptionalBoolean
Link copied to clipboard
fun orElse(default: Boolean): Boolean

returns default if the optional is Missing, or Value.value if is Value.

Link copied to clipboard

returns default if this is null, calls OptionalBoolean.asNullable otherwise.