# 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)

*** ** * ** ***


```
public static class StateStoreSerializer implements OkioSerializer<@NonNull StateStorePreferences>
```

<br />

*** ** * ** ***

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

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

## Summary

| ### Public fields |
|---|---|
| `static @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appstate/datastore/StateStoreSerializer` | `https://developer.android.com/reference/androidx/appstate/datastore/StateStoreSerializer#INSTANCE()` |

| ### Public methods |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appstate/datastore/StateStorePreferences` | `https://developer.android.com/reference/androidx/appstate/datastore/StateStoreSerializer#getDefaultValue()()` Value to return if there is no data on disk. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appstate/datastore/StateStorePreferences` | `https://developer.android.com/reference/androidx/appstate/datastore/StateStoreSerializer#readFrom(okio.BufferedSource)(@https://developer.android.com/reference/androidx/annotation/NonNull https://lysine.dev/okio/3.x/okio/okio/-buffered-source/index.html source)` Unmarshal object from source. |
| `void` | `https://developer.android.com/reference/androidx/appstate/datastore/StateStoreSerializer#writeTo(androidx.appstate.datastore.StateStorePreferences,okio.BufferedSink)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appstate/datastore/StateStorePreferences t, @https://developer.android.com/reference/androidx/annotation/NonNull https://lysine.dev/okio/3.x/okio/okio/-buffered-sink/index.html sink)` Marshal object to a Sink. |

## Public fields

### INSTANCE

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

```
public static @NonNull StateStoreSerializer INSTANCE
```

## Public methods

### getDefaultValue

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

```
public @NonNull StateStorePreferences getDefaultValue()
```

Value to return if there is no data on disk.

### readFrom

```
public @NonNull StateStorePreferences readFrom(@NonNull BufferedSource source)
```

Unmarshal object from source.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://lysine.dev/okio/3.x/okio/okio/-buffered-source/index.html source` | the BufferedSource with the data to deserialize |

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

### writeTo

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

```
public void writeTo(@NonNull StateStorePreferences t, @NonNull BufferedSink sink)
```

Marshal object to a Sink.

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