DecodeSequenceMode

Description of JSON input shape used for decoding to sequence.

The sequence represents a stream of objects parsed one by one; DecodeSequenceMode defines a separator between these objects. Typically, these objects are not separated by meaningful characters (WHITESPACE_SEPARATED), or the whole stream is a large array of objects separated with commas (ARRAY_WRAPPED).

It is used in Json.decodeToSequence family of functions:

@Serializable
data class Game(val name: String)
val input = """{"name": "Gothic"} {"name": "Planescape"} {"name": "Fallout"}"""
// On multiplatform, Okio's Source can be used
val inputStream = ByteArrayInputStream(input.encodeToByteArray())

val sequence = Json.decodeToSequence<Game>(inputStream, DecodeSequenceMode.WHITESPACE_SEPARATED)
// Prints Game(name=Gothic), Game(name=Planescape) and Game(name=Fallout)
for (game in sequence) {
println(game)
}

Entries

Link copied to clipboard

Declares that objects in the input stream are separated by whitespace characters.

Link copied to clipboard

Declares that objects in the input stream are wrapped in the JSON array. Each individual object in the array is parsed lazily when it is requested from the resulting sequence.

Link copied to clipboard

Declares that parser itself should select between WHITESPACE_SEPARATED and ARRAY_WRAPPED modes. The selection is performed by looking at the first meaningful character of the stream.

Properties

Link copied to clipboard

Returns a representation of an immutable list of all enum entries, in the order they're declared.

Link copied to clipboard
expect val name: String
Link copied to clipboard
expect val ordinal: Int

Functions

Link copied to clipboard

Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Link copied to clipboard

Returns an array containing the constants of this enum type, in the order they're declared.