Class JsonUtil

java.lang.Object
io.github.alejo2075.enzonasdk.util.JsonUtil

public class JsonUtil extends Object
Provides utility methods for converting between JSON strings and Java objects. This class configures the ObjectMapper to not fail on unknown properties and to format the JSON output.

Exception handling is centralized via the JsonProcessingException, providing a clear protocol for error management across JSON processing tasks.

  • Constructor Details

    • JsonUtil

      public JsonUtil()
  • Method Details

    • fromJson

      public static <T> T fromJson(String json, Class<T> valueType)
      Deserializes a JSON string into an object of the specified Java class.
      Type Parameters:
      T - the type parameter indicating the type of the Java object to be returned
      Parameters:
      json - the JSON string to be deserialized
      valueType - the class of type T to which json is to be deserialized
      Returns:
      an instance of T populated with data converted from the JSON string
      Throws:
      JsonProcessingException - if JSON to Java object deserialization fails
    • toJson

      public static String toJson(Object value)
      Serializes an object into its JSON string representation.
      Parameters:
      value - the Java object to be serialized
      Returns:
      a JSON string representation of value
      Throws:
      JsonProcessingException - if object to JSON serialization fails