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: KSerializer<T>)
Cmn

Public functions

open MutableStateFlow<T>
deserialize(decoder: Decoder)
Cmn
open Unit
serialize(encoder: Encoder, value: MutableStateFlow<T>)
Cmn

Public properties

open SerialDescriptor
Cmn

Public constructors

MutableStateFlowSerializer

<T : Any?> MutableStateFlowSerializer(valueSerializer: KSerializer<T>)
Parameters
<T : Any?>

The type of the value stored in the MutableStateFlow.

valueSerializer: KSerializer<T>

The KSerializer used to serialize and deserialize the inner value.

Public functions

deserialize

open fun deserialize(decoder: Decoder): MutableStateFlow<T>

serialize

open fun serialize(encoder: Encoder, value: MutableStateFlow<T>): Unit

Public properties

descriptor

open val descriptorSerialDescriptor