Class GJson

java.lang.Object
com.glitchybyte.glib.json.GJson

public final class GJson extends Object
A wrapper around a Gson object that extends its capabilities.

Just like Gson, a GJson object is thread-safe.

  • Constructor Details

    • GJson

      public GJson(com.google.gson.Gson gson)
      Creates a json helper wrapper around a Gson object.
      Parameters:
      gson - Actual Gson object doing json work.
  • Method Details

    • defaultInstance

      public static GJson defaultInstance()
      Returns a singleton default basic GJson.
      Returns:
      A singleton default basic GJson.
    • prettyInstance

      public static GJson prettyInstance()
      Returns a singleton GJson with pretty printing.
      Returns:
      A singleton GJson with pretty printing.
    • fromString

      public <T> T fromString(String json, Class<T> tClass)
      Create object from String.
      Type Parameters:
      T - Type of desired object.
      Parameters:
      json - Json string.
      tClass - Class of resulting object.
      Returns:
      Object populated from json.
    • fromString

      public <T> T fromString(String json, Type type)
      Create object from String.
      Type Parameters:
      T - Type of desired object.
      Parameters:
      json - Json string.
      type - Type of resulting object.
      Returns:
      Object populated from json.
    • fromPath

      public <T> T fromPath(String path, Class<T> tClass)
      Create object from String representation 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

      public <T> T fromPath(String path, Type type)
      Create object from String representation 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

      public <T> T fromFile(File file, Class<T> tClass)
      Create object from File.
      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

      public <T> T fromFile(File file, Type type)
      Create object from File.
      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

      public <T> T fromPath(Path path, Class<T> tClass)
      Create object from Path.
      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

      public <T> T fromPath(Path path, Type type)
      Create object from Path.
      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

      public <T> T fromInputStream(InputStream stream, Class<T> tClass)
      Create object from InputStream.
      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

      public <T> T fromInputStream(InputStream stream, Type type)
      Create object from InputStream.
      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

      public <T> T fromReader(Reader reader, Class<T> tClass)
      Create object from Reader.
      Type Parameters:
      T - Type of desired object.
      Parameters:
      reader - Reader producing json.
      tClass - Class of resulting object.
      Returns:
      Object populated from json.
    • fromReader

      public <T> T fromReader(Reader reader, Type type)
      Create object from Reader.
      Type Parameters:
      T - Type of desired object.
      Parameters:
      reader - Reader producing json.
      type - Type of resulting object.
      Returns:
      Object populated from json.
    • toString

      public String toString(Object object)
      Return object as json String.
      Parameters:
      object - Object to convert to json.
      Returns:
      Json string.
    • toPath

      public void toPath(Object object, String path)
      Write json object to path represented by a String.
      Parameters:
      object - Object to convert to json and write.
      path - String representation of the path to write json to.
    • toFile

      public void toFile(Object object, File file)
      Write json object to File.
      Parameters:
      object - Object to convert to json and write.
      file - File to write json to.
    • toPath

      public void toPath(Object object, Path path)
      Write json object to Path.
      Parameters:
      object - Object to convert to json and write.
      path - Path to write json to.
    • toWriter

      public void toWriter(Object object, Writer writer)
      Write json object to Writer.
      Parameters:
      object - Object to convert to json and write.
      writer - Writer to write json to.