Class JsonFileToObjectExtensions


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

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T toObject​(java.io.File jsonFile, java.lang.Class<T> clazz)
      Transforms the given json file into a java object
      static <T> T toObject​(java.io.File jsonFile, java.lang.Class<T> clazz, com.google.gson.Gson gson)
      Transforms the given json file into a java object.
      static <T> java.util.List<T> toObjectList​(java.io.File jsonListFile, java.lang.Class<T> clazz)
      Transforms the given json file into a java List object
      static <T> java.util.List<T> toObjectList​(java.io.File jsonListFile, java.lang.Class<T> clazz, com.google.gson.Gson gson)
      Transforms the given json file into a java List object
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • toObject

        public static <T> T toObject​(java.io.File jsonFile,
                                     java.lang.Class<T> clazz)
                              throws java.io.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:
        java.io.IOException - Signals that an I/O exception has occurred
      • toObject

        public static <T> T toObject​(java.io.File jsonFile,
                                     java.lang.Class<T> clazz,
                                     com.google.gson.Gson gson)
                              throws java.io.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:
        java.io.IOException - Signals that an I/O exception has occurred
      • toObjectList

        public static <T> java.util.List<T> toObjectList​(java.io.File jsonListFile,
                                                         java.lang.Class<T> clazz)
                                                  throws java.io.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:
        java.io.IOException - Signals that an I/O exception has occurred
      • toObjectList

        public static <T> java.util.List<T> toObjectList​(java.io.File jsonListFile,
                                                         java.lang.Class<T> clazz,
                                                         com.google.gson.Gson gson)
                                                  throws java.io.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:
        java.io.IOException - Signals that an I/O exception has occurred