---
title: "rememberSerializable"
description: "Remember the value produced by [init], and persist it across activity or process recreation using
a [KSerializer] for saving and restoring via the saved instance state mechanism.

This function automatically finds a [KSerializer] for the `reified` type `T`, making it a
convenient way to use [rememberSaveable] with types that are [Serializable].

This behaves similarly to [remember], but will survive configuration changes (such as screen
rotations) and process death by saving the value into the instance state."
type: "composable"
---

<div class='type'>Composable Function</div>


<a id='references'></a>

<div class='sourceset sourceset-common'>Common</div>


```kotlin
@Composable
public inline fun <reified T : Any> rememberSerializable(
    vararg inputs: Any?,
    configuration: SavedStateConfiguration = DEFAULT,
    noinline init: () -> T,
): T
```


Remember the value produced by `init`, and persist it across activity or process recreation using
a `KSerializer` for saving and restoring via the saved instance state mechanism.

This function automatically finds a `KSerializer` for the `reified` type `T`, making it a
convenient way to use `rememberSaveable` with types that are `Serializable`.

This behaves similarly to `remember`, but will survive configuration changes (such as screen
rotations) and process death by saving the value into the instance state.

#### Parameters

| | |
| --- | --- |
| inputs | A set of inputs which, when changed, will cause the stored state to reset and `init` to be re-executed. Note that previously saved values are not validated against these inputs during restoration. |
| configuration | Optional `SavedStateConfiguration` to customize how the serialized data is stored and restored. Defaults to `SavedStateConfiguration.DEFAULT`. |
| init | A factory function used to provide the initial value when no previously saved value exists. |


#### Returns

| | |
| --- | --- |
|  | The remembered and possibly restored value. |




<div class='sourceset sourceset-common'>Common</div>


```kotlin
@Composable
public fun <T : Any> rememberSerializable(
    vararg inputs: Any?,
    serializer: KSerializer<T>,
    configuration: SavedStateConfiguration = DEFAULT,
    init: () -> T,
): T
```


Remember the value produced by `init`, and persist it across activity or process recreation using
a `KSerializer` for saving and restoring via the saved instance state mechanism.

This behaves similarly to `remember`, but will survive configuration changes (such as screen
rotations) and process death by saving the value into the instance state using a serializer from
Kotlinx Serialization.

The value will be serialized using the provided `serializer`, and the way it's saved can be
customized using `configuration`.

If the type cannot be automatically handled by a default `Saver`, this overload provides a
simpler and type-safe way to persist complex or custom types using Kotlinx Serialization.

#### Parameters

| | |
| --- | --- |
| inputs | A set of inputs which, when changed, will cause the stored state to reset and `init` to be re-executed. Note that previously saved values are not validated against these inputs during restoration. |
| serializer | A `KSerializer` used to serialize and deserialize the value. |
| configuration | Optional `SavedStateConfiguration` to customize how the serialized data is stored and restored. Defaults to `SavedStateConfiguration.DEFAULT`. |
| init | A factory function used to provide the initial value when no previously saved value exists. |


#### Returns

| | |
| --- | --- |
|  | The remembered and possibly restored value. |




<div class='sourceset sourceset-common'>Common</div>


```kotlin
@Composable
public inline fun <reified T : Any> rememberSerializable(
    vararg inputs: Any?,
    configuration: SavedStateConfiguration = DEFAULT,
    noinline init: () -> MutableState<T>,
): MutableState<T>
```


Remember a `MutableState` produced by `init`, and persist it across activity or process
recreation using a `KSerializer` from `kotlinx.serialization`.

This function automatically finds a `KSerializer` for the `reified` type `T`, making it a
convenient way to use `rememberSaveable` with types that are `Serializable`.

This behaves similarly to `remember`, but the state will survive configuration changes (like
screen rotations) and process recreation. It is designed for state types that cannot be stored in
a `Bundle` directly but can be serialized.

#### Parameters

| | |
| --- | --- |
| inputs | A set of inputs which, when changed, will cause the stored state to reset and `init` to be re-executed. Note that previously saved values are not validated against these inputs during restoration. |
| configuration | Optional `SavedStateConfiguration` to customize how the serialization is handled, such as specifying a custom format (e.g. JSON). Defaults to `SavedStateConfiguration.DEFAULT`. |
| init | A factory function to produce the initial `MutableState` to be remembered. |


#### Returns

| | |
| --- | --- |
|  | The remembered and possibly restored `MutableState`. |




<div class='sourceset sourceset-common'>Common</div>


```kotlin
@Composable
public fun <T : Any> rememberSerializable(
    vararg inputs: Any?,
    stateSerializer: KSerializer<T>,
    configuration: SavedStateConfiguration = DEFAULT,
    init: () -> MutableState<T>,
): MutableState<T>
```


Remember the value produced by `init`, and save it across activity or process recreation using a
`KSerializer` from kotlinx.serialization.

This behaves similarly to `remember`, but the value will survive configuration changes (like
screen rotations) and process recreation by saving it in the instance state using a
serialization-based mechanism.

This overload is intended for cases where the state type cannot be stored directly in a Bundle,
but can be serialized with `kotlinx.serialization.KSerializer`. This is particularly useful for
custom or complex data types that are `@Serializable`.

#### Parameters

| | |
| --- | --- |
| inputs | A set of inputs such that, when any of them have changed, the state will reset and `init` will be rerun. Note: state restoration does NOT validate against inputs used before the value was saved. |
| stateSerializer | A `KSerializer` used to serialize and deserialize the state value. The value must be a non-nullable type marked with `@Serializable`. |
| configuration | Optional `SavedStateConfiguration` to customize how the serialization is handled, such as specifying a custom format (e.g. JSON). |
| init | A factory function to produce the initial value to be remembered and saved. |





## Code Examples
### RememberSaveableWithSerializer
```kotlin
@Composable
fun RememberSaveableWithSerializer() {
    val holder = rememberSerializable(serializer = HolderSerializer) { Holder(0) }
}
```
### RememberSaveableWithSerializerAndMutableState
```kotlin
@Composable
fun RememberSaveableWithSerializerAndMutableState() {
    val holder =
        rememberSerializable(stateSerializer = HolderSerializer) { mutableStateOf(Holder(0)) }
}
```

