Package com.glitchybyte.glib.json
Class GJson
java.lang.Object
com.glitchybyte.glib.json.GJson
A wrapper around a Gson object that extends its capabilities.
Just like Gson, a GJson object is thread-safe.
-
Constructor Summary
ConstructorsConstructorDescriptionGJson(com.google.gson.Gson gson) Creates a json helper wrapper around aGsonobject. -
Method Summary
Modifier and TypeMethodDescriptionstatic GJsonReturns a singleton default basicGJson.<T> TCreate object fromFile.<T> TCreate object fromFile.<T> TfromInputStream(InputStream stream, Class<T> tClass) Create object fromInputStream.<T> TfromInputStream(InputStream stream, Type type) Create object fromInputStream.<T> TCreate object fromStringrepresentation of a path.<T> TCreate object fromStringrepresentation of a path.<T> TCreate object fromPath.<T> TCreate object fromPath.<T> TfromReader(Reader reader, Class<T> tClass) Create object fromReader.<T> TfromReader(Reader reader, Type type) Create object fromReader.<T> TfromString(String json, Class<T> tClass) Create object fromString.<T> TfromString(String json, Type type) Create object fromString.static GJsonReturns a singletonGJsonwith pretty printing.voidWrite json object toFile.voidWrite json object to path represented by aString.voidWrite json object toPath.Return object as jsonString.voidWrite json object toWriter.
-
Constructor Details
-
GJson
public GJson(com.google.gson.Gson gson) Creates a json helper wrapper around aGsonobject.- Parameters:
gson- Actual Gson object doing json work.
-
-
Method Details
-
defaultInstance
Returns a singleton default basicGJson.- Returns:
- A singleton default basic
GJson.
-
prettyInstance
Returns a singletonGJsonwith pretty printing.- Returns:
- A singleton
GJsonwith pretty printing.
-
fromString
Create object fromString.- Type Parameters:
T- Type of desired object.- Parameters:
json- Json string.tClass- Class of resulting object.- Returns:
- Object populated from json.
-
fromString
Create object fromString.- Type Parameters:
T- Type of desired object.- Parameters:
json- Json string.type- Type of resulting object.- Returns:
- Object populated from json.
-
fromPath
Create object fromStringrepresentation of a path.- Type Parameters:
T- Type of desired object.- Parameters:
path- String representation of the path to read json from.tClass- Class of resulting object.- Returns:
- Object populated from json.
-
fromPath
Create object fromStringrepresentation of a path.- Type Parameters:
T- Type of desired object.- Parameters:
path- String representation of the path to read json from.type- Type of resulting object.- Returns:
- Object populated from json.
-
fromFile
Create object fromFile.- Type Parameters:
T- Type of desired object.- Parameters:
file- File to read json from.tClass- Class of resulting object.- Returns:
- Object populated from json.
-
fromFile
Create object fromFile.- Type Parameters:
T- Type of desired object.- Parameters:
file- File to read json from.type- Type of resulting object.- Returns:
- Object populated from json.
-
fromPath
Create object fromPath.- Type Parameters:
T- Type of desired object.- Parameters:
path- Path to read json from.tClass- Class of resulting object.- Returns:
- Object populated from json.
-
fromPath
Create object fromPath.- Type Parameters:
T- Type of desired object.- Parameters:
path- Path to read json from.type- Type of resulting object.- Returns:
- Object populated from json.
-
fromInputStream
Create object fromInputStream.- Type Parameters:
T- Type of desired object.- Parameters:
stream- InputStream to read json from.tClass- Class of resulting object.- Returns:
- Object populated from json.
-
fromInputStream
Create object fromInputStream.- Type Parameters:
T- Type of desired object.- Parameters:
stream- InputStream to read json from.type- Type of resulting object.- Returns:
- Object populated from json.
-
fromReader
Create object fromReader.- Type Parameters:
T- Type of desired object.- Parameters:
reader- Reader producing json.tClass- Class of resulting object.- Returns:
- Object populated from json.
-
fromReader
Create object fromReader.- Type Parameters:
T- Type of desired object.- Parameters:
reader- Reader producing json.type- Type of resulting object.- Returns:
- Object populated from json.
-
toString
Return object as jsonString.- Parameters:
object- Object to convert to json.- Returns:
- Json string.
-
toPath
Write json object to path represented by aString.- Parameters:
object- Object to convert to json and write.path- String representation of the path to write json to.
-
toFile
Write json object toFile.- Parameters:
object- Object to convert to json and write.file- File to write json to.
-
toPath
Write json object toPath.- Parameters:
object- Object to convert to json and write.path- Path to write json to.
-
toWriter
Write json object toWriter.- Parameters:
object- Object to convert to json and write.writer- Writer to write json to.
-