OptionalVariable

sealed interface OptionalVariable<out T>(source)

A variable of an operation that may be left undefined, which is distinct from null: an Undefined variable is not sent to the server at all (and takes the operation's default), a Value is sent even when it holds null.

Inheritors

Types

Link copied to clipboard
class Serializer<T>(elementSerializer: KSerializer<T>) : KSerializer<OptionalVariable<T>>

Serializes a Value with elementSerializer and an Undefined as nothing at all, so that the field is absent from the encoded variables. Only encoders that tolerate an element encoding nothing support this (the tree encoder of kotlinx-serialization-json does, its streaming encoder does not). Decoding is not supported, as variables are only ever sent.

Link copied to clipboard

The undefined variable: omitted when the variables are serialized.

Link copied to clipboard
class Value<T>(val value: T) : OptionalVariable<T>

A defined variable, possibly holding null.

Functions

Link copied to clipboard
abstract fun valueOrNull(): T?

The value, or null when undefined.

Link copied to clipboard
abstract fun valueOrThrow(): T

The value; throws when undefined.