Serializer

public interface Serializer<T extends Object>


The serializer determines the on-disk format and API for accessing it.

The type T MUST be immutable. Mutable types will result in broken DataStore functionality.

TODO(b/151635324): consider changing InputStream to File.

Summary

Public methods

abstract @NonNull T

Value to return if there is no data on disk.

abstract @NonNull T

Unmarshal object from stream.

abstract void

Marshal object to a stream.

Public methods

getDefaultValue

Added in 1.0.0
abstract @NonNullgetDefaultValue()

Value to return if there is no data on disk.

readFrom

abstract @NonNullreadFrom(@NonNull InputStream input)

Unmarshal object from stream.

Parameters
@NonNull InputStream input

the InputStream with the data to deserialize

writeTo

Added in 1.0.0
abstract void writeTo(@NonNull T t, @NonNull OutputStream output)

Marshal object to a stream. Closing the provided OutputStream is a no-op.

the OutputStream to serialize data to

Parameters
@NonNull T t

the data to write to output