Box
Box is generic container for type T, which can be marked as absent (empty). Behaves similarly to Java's Optional, but allows nullable types as well.
Primary usage is to mark properties in kotlinx.serialization as nullable and optional at the same time, to be able to serialize nulls when schema requires it (for example in many request bodies for patch/edit requests) and still have some "default" value (in this case Box.absent) to omit property in serialization process.
@Serializable
data class SomePojo(
// Now we can omit property as it is optional,
// but serialize nulls as-well.
val property: Box<String?> = Box.absent
)Content copied to clipboard
Constructors
Types
Functions
Properties
Link copied to clipboard
Returns underlying value of type T or throws NoSuchElementException if this box is absent.