Class JsonUtil
java.lang.Object
com.github.silent.samurai.speedy.api.client.utils.JsonUtil
Utility class for JSON operations in the Speedy Java Client.
This is a library-agnostic utility that only handles JSON serialization/deserialization.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TConvert a JsonNode to a specific type.static <T> TConvert a JSON string to a specific type.static com.fasterxml.jackson.databind.ObjectMapperGet the ObjectMapper instance.static com.fasterxml.jackson.databind.JsonNodeParse a JSON string to JsonNode.static StringConvert an object to JSON string.
-
Constructor Details
-
JsonUtil
public JsonUtil()
-
-
Method Details
-
getObjectMapper
public static com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()Get the ObjectMapper instance.- Returns:
- the configured ObjectMapper
-
toJson
Convert an object to JSON string.- Parameters:
value- the object to convert- Returns:
- JSON string representation
- Throws:
com.fasterxml.jackson.core.JsonProcessingException- if conversion fails
-
fromJson
public static <T> T fromJson(com.fasterxml.jackson.databind.JsonNode jsonNode, Class<T> type) throws com.fasterxml.jackson.core.JsonProcessingException Convert a JsonNode to a specific type.- Type Parameters:
T- the target type- Parameters:
jsonNode- the JsonNode to converttype- the target class- Returns:
- the converted object
- Throws:
com.fasterxml.jackson.core.JsonProcessingException- if conversion fails
-
fromJson
public static <T> T fromJson(String json, Class<T> type) throws com.fasterxml.jackson.core.JsonProcessingException Convert a JSON string to a specific type.- Type Parameters:
T- the target type- Parameters:
json- the JSON stringtype- the target class- Returns:
- the converted object
- Throws:
com.fasterxml.jackson.core.JsonProcessingException- if conversion fails
-
parseJson
public static com.fasterxml.jackson.databind.JsonNode parseJson(String json) throws com.fasterxml.jackson.core.JsonProcessingException Parse a JSON string to JsonNode.- Parameters:
json- the JSON string- Returns:
- the JsonNode
- Throws:
com.fasterxml.jackson.core.JsonProcessingException- if parsing fails
-