Package utils
Class JsonUtils
java.lang.Object
utils.JsonUtils
Utility class for JSON serialization and deserialization.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
Reads and converts a JSON file from the classpath to an object of the specified class.jsonFileToMap
(String filename) Converts a JSON file from the classpath to a Map.static <T> String
JsonStringify
(T object) Serializes a Java object to its JSON string representation.static String
Converts a Map to a JSON string.
-
Constructor Details
-
JsonUtils
public JsonUtils()
-
-
Method Details
-
JsonStringify
Serializes a Java object to its JSON string representation.- Type Parameters:
T
- the type of the object- Parameters:
object
- the object to serialize- Returns:
- the JSON string, or null if serialization fails
-
mapToJson
Converts a Map to a JSON string.- Parameters:
map
- the Map- Returns:
- a JSOn String representation of the Map, or an empty string if conversion fails
-
jsonFileToMap
Converts a JSON file from the classpath to a Map.- Parameters:
filename
- the name of the JSON file in the classpath- Returns:
- a Map representation of the JSON, or an empty map if conversion fails
-
fromJson
Reads and converts a JSON file from the classpath to an object of the specified class.- Type Parameters:
T
- the type of object to convert to- Parameters:
filename
- the name of the JSON file in the classpathclazz
- the class of the target objectisFile
- whether the input is a file (unused parameter)- Returns:
- an instance of the target class, or null if the file is not found or conversion fails
-