Class JsonReadWriteUtils
java.lang.Object
edu.university.ecs.lab.common.utils.JsonReadWriteUtils
Utility class for reading and writing JSON to a file.
-
Constructor Summary
ModifierConstructorDescriptionprivate
Private constructor to prevent instantiation. -
Method Summary
Modifier and TypeMethodDescriptionstatic <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.static com.google.gson.Gson
Function for register custom deserializers when reading JSON from a filestatic <T> void
writeToJSON
(String filePath, T object) Writes an object to a JSON file at a specified path.
-
Constructor Details
-
JsonReadWriteUtils
private JsonReadWriteUtils()Private constructor to prevent instantiation.
-
-
Method Details
-
writeToJSON
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 JSONfilePath
- the file path where the JSON should be saved
-
readFromJSON
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 filetype
- the Class representing the type of the object to deserialize- Returns:
- an object of type T containing the data from the JSON file
-
registerDeserializers
public static com.google.gson.Gson registerDeserializers()Function for register custom deserializers when reading JSON from a file- Returns:
-