# MutableStateFlowSerializer

Artifact: [androidx.savedstate:savedstate](https://developer.android.com/jetpack/androidx/releases/savedstate) [View Source](https://cs.android.com/search?q=file:androidx/savedstate/serialization/serializers/MutableStateFlowSerializer.kt+class:androidx.savedstate.serialization.serializers.MutableStateFlowSerializer) Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/savedstate#1.3.0)

*** ** * ** ***

Common/AllAndroid/JVM
- Cmn

  ```
  class MutableStateFlowSerializer<T : Any?> : KSerializer<MutableStateFlow<T>>
  ```

*** ** * ** ***

A `https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization/-k-serializer/index.html` for `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-state-flow/index.html`.

This class wraps a `https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization/-k-serializer/index.html` for the inner value type `https://developer.android.com/reference/kotlin/androidx/savedstate/serialization/serializers/MutableStateFlowSerializer`, enabling serialization and deserialization of `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-state-flow/index.html` instances. The inner value serialization is delegated to the provided `https://developer.android.com/reference/kotlin/androidx/savedstate/serialization/serializers/MutableStateFlowSerializer#(kotlinx.serialization.KSerializer)`.

Note that the SavedState format uses this serializer automatically for a `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-state-flow/index.html` at root and there is no need to explicitly specify it. For example:

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

However, when the `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-state-flow/index.html` 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:

```kotlin
@Serializable
data class MyData(
    @Serializable(with = MutableStateFlowSerializer::class)
    val flow: MutableStateFlow<Int>
)
```

| Parameters |
|---|---|
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?>` | The type of the value stored in the `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-state-flow/index.html`. |

## Summary

| ### Public constructors |
|---|---|
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/savedstate/serialization/serializers/MutableStateFlowSerializer#MutableStateFlowSerializer(kotlinx.serialization.KSerializer)(valueSerializer: https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization/-k-serializer/index.html<T>)` | Cmn |

| ### Public functions |
|---|---|---|
| `open https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-state-flow/index.html<T>` | `https://developer.android.com/reference/kotlin/androidx/savedstate/serialization/serializers/MutableStateFlowSerializer#deserialize(kotlinx.serialization.encoding.Decoder)(decoder: https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization.encoding/-decoder/index.html)` | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/savedstate/serialization/serializers/MutableStateFlowSerializer#serialize(kotlinx.serialization.encoding.Encoder,kotlinx.coroutines.flow.MutableStateFlow)(encoder: https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization.encoding/-encoder/index.html, value: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-state-flow/index.html<T>)` | Cmn |

| ### Public properties |
|---|---|---|
| `open https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization.descriptors/-serial-descriptor/index.html` | `https://developer.android.com/reference/kotlin/androidx/savedstate/serialization/serializers/MutableStateFlowSerializer#descriptor()` | Cmn |

## Public constructors

### MutableStateFlowSerializer

Cmn

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

| Parameters |
|---|---|
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?>` | The type of the value stored in the `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-state-flow/index.html`. |
| `valueSerializer: https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization/-k-serializer/index.html<T>` | The `https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization/-k-serializer/index.html` used to serialize and deserialize the inner value. |

## Public functions

### deserialize

Cmn Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/savedstate#1.3.0)

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

### serialize

Cmn Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/savedstate#1.3.0)

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

## Public properties

### descriptor

Cmn Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/savedstate#1.3.0)

```
open val descriptor: SerialDescriptor
```