Class JsonReadWriteUtils

java.lang.Object
edu.university.ecs.lab.common.utils.JsonReadWriteUtils

public class JsonReadWriteUtils extends Object
Utility class for reading and writing JSON to a file.
  • Method Details

    • writeToJSON

      public static <T> void writeToJSON(String filePath, T object)
      Writes an object to a JSON file at a specified path.
      Type Parameters:
      T - the type of the object to write
      Parameters:
      object - the object to serialize into JSON
      filePath - the file path where the JSON should be saved
    • readFromJSON

      public static <T> T readFromJSON(String filePath, Class<T> type)
      Reads a JSON file from a given path and converts it into an object of the specified type.
      Type Parameters:
      T - the type of the object to return
      Parameters:
      filePath - the file path to the JSON file
      type - the Class representing the type of the object to deserialize
      Returns:
      an object of type T containing the data from the JSON file