java.lang.Object
com.github.silent.samurai.speedy.api.client.utils.JsonUtil

public class JsonUtil extends Object
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T
    fromJson(com.fasterxml.jackson.databind.JsonNode jsonNode, Class<T> type)
    Convert a JsonNode to a specific type.
    static <T> T
    fromJson(String json, Class<T> type)
    Convert a JSON string to a specific type.
    static com.fasterxml.jackson.databind.ObjectMapper
    Get the ObjectMapper instance.
    static com.fasterxml.jackson.databind.JsonNode
    Parse a JSON string to JsonNode.
    static String
    toJson(Object value)
    Convert an object to JSON string.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public static String toJson(Object value) throws com.fasterxml.jackson.core.JsonProcessingException
      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 convert
      type - 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 string
      type - 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