public static class StateStoreSerializer implements OkioSerializer<@NonNull StateStorePreferences>


Serializer for StateStorePreferences using DataStore and Okio.

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

Summary

Public fields

static @NonNull StateStoreSerializer

Public methods

@NonNull StateStorePreferences

Value to return if there is no data on disk.

@NonNull StateStorePreferences

Unmarshal object from source.

void

Marshal object to a Sink.

Public fields

INSTANCE

Added in 1.0.0-alpha01
public static @NonNull StateStoreSerializer INSTANCE

Public methods

getDefaultValue

Added in 1.0.0-alpha01
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
@NonNull BufferedSource source

the BufferedSource with the data to deserialize

Throws
androidx.datastore.core.CorruptionException

if the data from source is corrupted and/or unparseable, e.g. InvalidProtocolBufferException when the type T is a protobuf message and it is corrupted. Other unrecoverable androidx.datastore.core.IOException from the file system should not be thrown as androidx.datastore.core.CorruptionException.

writeTo

Added in 1.0.0-alpha01
public void writeTo(@NonNull StateStorePreferences t, @NonNull BufferedSink sink)

Marshal object to a Sink.

Parameters
@NonNull StateStorePreferences t

the data to write to output

@NonNull BufferedSink sink

the BufferedSink to serialize data to