Package utils
Class JsonUtils
java.lang.Object
utils.JsonUtils
Utility class for JSON operations using Jackson ObjectMapper. Provides methods for converting
between JSON strings, input streams, and Java objects.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
Converts a JSON string to an object of the specified class.static <T> T
Reads and converts a JSON file from the classpath to an object of the specified class.jsonToMap
(InputStream inputStream) Converts a JSON input stream to a Map.Converts a JSON string to a Map.
-
Constructor Details
-
JsonUtils
public JsonUtils()
-
-
Method Details
-
jsonToMap
Converts a JSON string to a Map.- Parameters:
json
- the JSON string to convert- Returns:
- a Map representation of the JSON, or an empty map if conversion fails
-
jsonToMap
Converts a JSON input stream to a Map.- Parameters:
inputStream
- the input stream containing JSON data- Returns:
- a Map representation of the JSON, or an empty map if conversion fails
-
fromJson
Converts a JSON string to an object of the specified class.- Type Parameters:
T
- the type of object to convert to- Parameters:
json
- the JSON string to convertclazz
- the class of the target object- Returns:
- an instance of the target class, or null 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
-