Class JsonPathStorage<T>
java.lang.Object
com.github.startsmercury.simply.no.shading.util.storage.PathStorage<T>
com.github.startsmercury.simply.no.shading.util.storage.JsonPathStorage<T>
- Type Parameters:
T- the supported type for storing
- All Implemented Interfaces:
Storage<T>
A
JsonPathStorage is a concrete implementation of PathStorage
in that serialized state is stored in the JSON file format.-
Constructor Summary
ConstructorsConstructorDescriptionJsonPathStorage(Path path) Creates a newJsonPathStoragewith a set path, defaulted gson, and without runtime type-checking.JsonPathStorage(Path path, com.google.gson.Gson gson) Creates a newJsonPathStoragewith a set path, gson, and without runtime type-checking.JsonPathStorage(Path path, com.google.gson.Gson gson, Class<T> clazz) Creates a newJsonPathStoragewith a set path, gson, and class.JsonPathStorage(Path path, Class<T> clazz) Creates a newJsonPathStoragewith a set path, defaulted gson, and class. -
Method Summary
Modifier and TypeMethodDescriptioncom.google.gson.GsongetGson()Returns the gson used for (de)serialization.protected final com.google.gson.GsonThis is a utility method wraps aroundgetGson(), returning when not null; returns a fallback otherwise.getType()Returns the supported type for storing.load()Loads the stored state as a new object.voidStores the state of a given object.Methods inherited from class com.github.startsmercury.simply.no.shading.util.storage.PathStorage
equals, getPath, hashCode, toString
-
Constructor Details
-
JsonPathStorage
Creates a newJsonPathStoragewith a set path, defaulted gson, and without runtime type-checking.- Parameters:
path- the path where object state is (de)serialized
-
JsonPathStorage
Creates a newJsonPathStoragewith a set path, defaulted gson, and class.- Parameters:
path- the path where object state is (de)serializedclazz- the supported type
-
JsonPathStorage
Creates a newJsonPathStoragewith a set path, gson, and without runtime type-checking.- Parameters:
path- the path where object state is (de)serializedgson- the gson used for (de)serialization
-
JsonPathStorage
Creates a newJsonPathStoragewith a set path, gson, and class.- Parameters:
path- the path where object state is (de)serializedgson- the gson used for (de)serializationclazz- the supported type
-
-
Method Details
-
getGson
public com.google.gson.Gson getGson()Returns the gson used for (de)serialization.- Returns:
- the gson used for (de)serialization
-
getGsonElseFallback
protected final com.google.gson.Gson getGsonElseFallback()This is a utility method wraps aroundgetGson(), returning when not null; returns a fallback otherwise.- Returns:
- the gson used for (de)serialization
-
getType
Returns the supported type for storing.- Returns:
- the supported type for storing
-
load
Loads the stored state as a new object.- Returns:
- a new object loaded with the stored state
- Throws:
Exception- thrown when an implementation encountered a checked exception; the actual type may depend on the implementationNullPointerException- thrown when an implementation does not recognizenullas a valid destination; usually it isn't
-
save
Stores the state of a given object.- Parameters:
obj- the object to store the state of- Throws:
Exception- thrown when an implementation encountered a checked exception; the actual type may depend on the implementationNullPointerException- thrown when an implementation does not recognizenullas a valid state to store
-