Serializer

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 fields

abstract @NonNull T

Value to return if there is no data on disk.

Public methods

abstract @NonNull T

Unmarshal object from stream.

abstract void

Marshal object to a stream.

Public fields

defaultValue

@NonNull
public abstract @NonNulldefaultValue

Value to return if there is no data on disk.

Public methods

readFrom

@NonNull
public abstract T readFrom(@NonNull InputStream input)

Unmarshal object from stream.

Parameters
@NonNull InputStream input

the InputStream with the data to deserialize

writeTo

@NonNull
public abstract void writeTo(@NonNull T t, @NonNull OutputStream output)

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

Parameters
@NonNull T t

the data to write to output