Class JsonFileToObjectExtensions

java.lang.Object
io.github.astrapi69.gson.JsonFileToObjectExtensions

public final class JsonFileToObjectExtensions extends Object
The class JsonFileToObjectExtensions converts json strings to java object and java collections.
  • Method Details

    • toObject

      public static <T> T toObject(File jsonFile, Class<T> clazz) throws IOException
      Transforms the given json file into a java object
      Type Parameters:
      T - the generic type
      Parameters:
      jsonFile - the json file
      clazz - the class
      Returns:
      the java object
      Throws:
      IOException - Signals that an I/O exception has occurred
    • toObject

      public static <T> T toObject(File jsonFile, Class<T> clazz, com.google.gson.Gson gson) throws IOException
      Transforms the given json file into a java object.
      Type Parameters:
      T - the generic type
      Parameters:
      jsonFile - the json file
      clazz - the class
      gson - the gson object
      Returns:
      the java object
      Throws:
      IOException - Signals that an I/O exception has occurred
    • toObjectList

      public static <T> List<T> toObjectList(File jsonListFile, Class<T> clazz) throws IOException
      Transforms the given json file into a java List object
      Type Parameters:
      T - the generic type
      Parameters:
      jsonListFile - the json file with an array
      clazz - the class
      Returns:
      the list
      Throws:
      IOException - Signals that an I/O exception has occurred
    • toObjectList

      public static <T> List<T> toObjectList(File jsonListFile, Class<T> clazz, com.google.gson.Gson gson) throws IOException
      Transforms the given json file into a java List object
      Type Parameters:
      T - the generic type
      Parameters:
      jsonListFile - the json file with an array
      clazz - the class
      gson - the gson object
      Returns:
      the list
      Throws:
      IOException - Signals that an I/O exception has occurred