T - the supported type for storingpublic class JsonPathStorage<T> extends PathStorage<T>
JsonPathStorage is a concrete implementation of PathStorage
in that serialized state is stored in the JSON file format.| Constructor and Description |
|---|
JsonPathStorage(java.nio.file.Path path)
Creates a new
JsonPathStorage with a set path, defaulted gson, and
without runtime type-checking. |
JsonPathStorage(java.nio.file.Path path,
java.lang.Class<T> clazz)
Creates a new
JsonPathStorage with a set path, defaulted gson, and
class. |
JsonPathStorage(java.nio.file.Path path,
com.google.gson.Gson gson)
Creates a new
JsonPathStorage with a set path, gson, and without
runtime type-checking. |
JsonPathStorage(java.nio.file.Path path,
com.google.gson.Gson gson,
java.lang.Class<T> clazz)
Creates a new
JsonPathStorage with a set path, gson, and class. |
| Modifier and Type | Method and Description |
|---|---|
com.google.gson.Gson |
getGson()
Returns the gson used for (de)serialization.
|
protected com.google.gson.Gson |
getGsonElseFallback()
This is a utility method wraps around
getGson(), returning when not
null; returns a fallback otherwise. |
java.lang.reflect.Type |
getType()
Returns the supported type for storing.
|
T |
load()
Loads the stored state as a new object.
|
void |
save(T obj)
Stores the state of a given object.
|
equals, getPath, hashCode, toStringpublic JsonPathStorage(java.nio.file.Path path)
JsonPathStorage with a set path, defaulted gson, and
without runtime type-checking.path - the path where object state is (de)serializedpublic JsonPathStorage(java.nio.file.Path path,
java.lang.Class<T> clazz)
JsonPathStorage with a set path, defaulted gson, and
class.path - the path where object state is (de)serializedclazz - the supported typepublic JsonPathStorage(java.nio.file.Path path,
com.google.gson.Gson gson)
JsonPathStorage with a set path, gson, and without
runtime type-checking.path - the path where object state is (de)serializedgson - the gson used for (de)serializationpublic JsonPathStorage(java.nio.file.Path path,
com.google.gson.Gson gson,
java.lang.Class<T> clazz)
JsonPathStorage with a set path, gson, and class.path - the path where object state is (de)serializedgson - the gson used for (de)serializationclazz - the supported typepublic com.google.gson.Gson getGson()
protected final com.google.gson.Gson getGsonElseFallback()
getGson(), returning when not
null; returns a fallback otherwise.public java.lang.reflect.Type getType()
public T load() throws java.lang.Exception
java.lang.Exception - thrown when an implementation encountered a
checked exception; the actual type may depend on
the implementationjava.lang.NullPointerException - thrown when an implementation does not recognize
null as a valid destination; usually it
isn'tpublic void save(T obj) throws java.lang.Exception
obj - the object to store the state ofjava.lang.Exception - thrown when an implementation encountered a
checked exception; the actual type may depend on
the implementationjava.lang.NullPointerException - thrown when an implementation does not recognize
null as a valid state to store