MutableStateFlowSerializer



A KSerializer for MutableStateFlow.

This class wraps a KSerializer for the inner value type T, enabling serialization and deserialization of MutableStateFlow instances. The inner value serialization is delegated to the provided valueSerializer.

Note that the SavedState format uses this serializer automatically for a MutableStateFlow at root and there is no need to explicitly specify it. For example:

val msf = MutableStateFlow(123)
// No need to do `encodeToSavedState(MutableStateFlowSerializer(Int.serializer), msf)`
encodeToSavedState(msf)

However, when the MutableStateFlow is a property of a serializable class there is no automatic fallback and a Serializable annotation is still needed if the property is intended to be serialized with this serializer. For example:

@Serializable
data
class MyData(
@Serializable(with = MutableStateFlowSerializer::class)
val flow: MutableStateFlow<Int>
)
Parameters
<T : Any?>

The type of the value stored in the MutableStateFlow.

Summary

Public constructors

<T : Any?> MutableStateFlowSerializer(
    valueSerializer: <Error class: unknown class><T>
)
Cmn

Public functions

open MutableStateFlow<T>
Cmn
open Unit
serialize(
    encoder: <Error class: unknown class>,
    value: MutableStateFlow<T>
)
Cmn

Public properties

open <Error class: unknown class>
Cmn

Public constructors

MutableStateFlowSerializer

<T : Any?> MutableStateFlowSerializer(
    valueSerializer: <Error class: unknown class><T>
)
Parameters
<T : Any?>

The type of the value stored in the MutableStateFlow.

valueSerializer: <Error class: unknown class><T>

The KSerializer used to serialize and deserialize the inner value.

Public functions

deserialize

open fun deserialize(decoder: <Error class: unknown class>): MutableStateFlow<T>

serialize

open fun serialize(
    encoder: <Error class: unknown class>,
    value: MutableStateFlow<T>
): Unit

Public properties

descriptor

open val descriptor<Error class: unknown class>