Package valorless.valorlessutils.json
Class JsonUtils
java.lang.Object
valorless.valorlessutils.json.JsonUtils
Utility class for working with JSON using Gson.
Provides methods for serializing and deserializing objects,
including pretty-printing and Bukkit-aware handling.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> @Nullable T
Deserializes a JSON string into an object using Bukkit-aware handling.static <T> T
fromPlainJson
(@Nullable String json) Deserializes a JSON string into a plain Java object.static String
Converts an object to a JSON string using the standard Gson instance.static String
toPrettyJson
(@Nullable Object object) Converts an object to a pretty-printed JSON string.
-
Method Details
-
toJson
Converts an object to a JSON string using the standard Gson instance. The object may be a primitive, Map, List, null, or custom supported types.- Parameters:
object
- The object to serialize (nullable)- Returns:
- JSON string representation
-
toPrettyJson
Converts an object to a pretty-printed JSON string.- Parameters:
object
- The object to serialize (nullable)- Returns:
- JSON string with pretty formatting
-
fromPlainJson
Deserializes a JSON string into a plain Java object. Does not handle ConfigurationSerializable objects.- Type Parameters:
T
- The expected return type- Parameters:
json
- JSON string to deserialize- Returns:
- Deserialized object
- Throws:
IllegalArgumentException
- if deserialization fails
-
fromJson
Deserializes a JSON string into an object using Bukkit-aware handling. Can deserialize ConfigurationSerializable objects.- Type Parameters:
T
- The expected return type- Parameters:
json
- JSON string to deserialize- Returns:
- Deserialized object or null if input is null
- Throws:
IllegalArgumentException
- if deserialization fails
-