# StateStoreSerializer

Artifact: [androidx.appstate.statestore:statestore-datastore](https://developer.android.com/jetpack/androidx/releases/appstate-statestore) [View Source](https://cs.android.com/search?q=file:androidx/appstate/datastore/StateStoreDataStore.kt+class:androidx.appstate.datastore.StateStoreSerializer) Added in [1.0.0-alpha02](https://developer.android.com/jetpack/androidx/releases/appstate-statestore#1.0.0-alpha02)

*** ** * ** ***


```
object StateStoreSerializer : OkioSerializer<StateStorePreferences>
```

<br />

*** ** * ** ***

Serializer for `https://developer.android.com/reference/kotlin/androidx/appstate/datastore/StateStorePreferences` using `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore` and Okio.

Serializes the preferences to a JSON string backed by a UTF-8 file.

## Summary

| ### Public functions |
|---|---|
| `open suspend https://developer.android.com/reference/kotlin/androidx/appstate/datastore/StateStorePreferences` | `https://developer.android.com/reference/kotlin/androidx/appstate/datastore/StateStoreSerializer#readFrom(okio.BufferedSource)(source: https://lysine.dev/okio/3.x/okio/okio/-buffered-source/index.html)` Unmarshal object from source. |
| `open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/appstate/datastore/StateStoreSerializer#writeTo(androidx.appstate.datastore.StateStorePreferences,okio.BufferedSink)(t: https://developer.android.com/reference/kotlin/androidx/appstate/datastore/StateStorePreferences, sink: https://lysine.dev/okio/3.x/okio/okio/-buffered-sink/index.html)` Marshal object to a Sink. |

| ### Public properties |
|---|---|
| `open https://developer.android.com/reference/kotlin/androidx/appstate/datastore/StateStorePreferences` | `https://developer.android.com/reference/kotlin/androidx/appstate/datastore/StateStoreSerializer#defaultValue()` Value to return if there is no data on disk. |

## Public functions

### readFrom

```
open suspend fun readFrom(source: BufferedSource): StateStorePreferences
```

Unmarshal object from source.

| Parameters |
|---|---|
| `source: https://lysine.dev/okio/3.x/okio/okio/-buffered-source/index.html` | the BufferedSource with the data to deserialize |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/CorruptionException` | if the data from `https://developer.android.com/reference/kotlin/androidx/datastore/core/okio/OkioSerializer#readFrom(okio.BufferedSource)` is corrupted and/or unparseable, e.g. `InvalidProtocolBufferException` when the type `https://developer.android.com/reference/kotlin/androidx/datastore/core/okio/OkioSerializer` is a protobuf message and it is corrupted. Other unrecoverable `https://developer.android.com/reference/kotlin/androidx/datastore/core/IOException` from the file system should not be thrown as `https://developer.android.com/reference/kotlin/androidx/datastore/core/CorruptionException`. |

### writeTo

Added in [1.0.0-alpha02](https://developer.android.com/jetpack/androidx/releases/appstate-statestore#1.0.0-alpha02)

```
open suspend fun writeTo(t: StateStorePreferences, sink: BufferedSink): Unit
```

Marshal object to a Sink.

| Parameters |
|---|---|
| `t: https://developer.android.com/reference/kotlin/androidx/appstate/datastore/StateStorePreferences` | the data to write to output |
| `sink: https://lysine.dev/okio/3.x/okio/okio/-buffered-sink/index.html` | the BufferedSink to serialize data to |

## Public properties

### defaultValue

Added in [1.0.0-alpha02](https://developer.android.com/jetpack/androidx/releases/appstate-statestore#1.0.0-alpha02)

```
open val defaultValue: StateStorePreferences
```

Value to return if there is no data on disk.