A Serializer that uses kotlinx.serialization.json to convert any @Serializable data class T to and from a byte stream using Okio.

Parameters
<T : Any?>

The data type to serialize. Must be annotated with @Serializable.

Summary

Public constructors

<T : Any?> WebSerializer(
    kSerializer: <Error class: unknown class><T>,
    defaultValue: T
)
JS

Public functions

open suspend T

Reads a UTF-8 string from the source, and then parses that string back into an object of type T using JSON.

JS
open suspend Unit
writeTo(t: T, sink: BufferedSink)

Encodes the object of type T into a JSON string, and writes that UTF-8 string to the sink.

JS

Public properties

open T

The default instance of T to return if data is corrupted or doesn't exist.

JS

Public constructors

WebSerializer

<T : Any?> WebSerializer(
    kSerializer: <Error class: unknown class><T>,
    defaultValue: T
)
Parameters
<T : Any?>

The data type to serialize. Must be annotated with @Serializable.

kSerializer: <Error class: unknown class><T>

The KSerializer for type T, usually accessed via T.serializer().

defaultValue: T

The default instance of T to return if data is corrupted or doesn't exist.

Public functions

readFrom

open suspend fun readFrom(source: BufferedSource): T

Reads a UTF-8 string from the source, and then parses that string back into an object of type T using JSON.

writeTo

open suspend fun writeTo(t: T, sink: BufferedSink): Unit

Encodes the object of type T into a JSON string, and writes that UTF-8 string to the sink.

Public properties

defaultValue

open val defaultValue: T

The default instance of T to return if data is corrupted or doesn't exist.