---
title: "mapSaver"
description: "The [Saver] implementation which allows to represent your class as a map of values which can be
saved individually.

What types can be saved is defined by [SaveableStateRegistry], by default everything which can be
stored in the Bundle class can be saved.

You can use it as a parameter for [rememberSaveable]."
type: "function"
---

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


<a id='references'></a>
<div class='sourceset sourceset-common'>Common</div>


```kotlin
public fun <T> mapSaver(
    save: SaverScope.(value: T) -> Map<String, Any?>,
    restore: (Map<String, Any?>) -> T?,
): Saver<T, Any>
```


The `Saver` implementation which allows to represent your class as a map of values which can be
saved individually.

What types can be saved is defined by `SaveableStateRegistry`, by default everything which can be
stored in the Bundle class can be saved.

You can use it as a parameter for `rememberSaveable`.



## Code Examples
### MapSaverSample
```kotlin
@Composable
fun MapSaverSample() {
    data class User(val name: String, val age: Int)
    val userSaver = run {
        val nameKey = "Name"
        val ageKey = "Age"
        mapSaver(
            save = { mapOf(nameKey to it.name, ageKey to it.age) },
            restore = { User(it[nameKey] as String, it[ageKey] as Int) },
        )
    }
}
```

