Class JacksonUtils

java.lang.Object
org.hisp.dhis.util.JacksonUtils

public class JacksonUtils extends Object
  • Constructor Details

    • JacksonUtils

      public JacksonUtils()
  • Method Details

    • getObjectMapper

      public static com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
      Returns an ObjectMapper.
      Returns:
      an ObjectMapper.
    • toJsonString

      public static String toJsonString(Object value)
      Serializes the given object to JSON and returns the result as a String.
      Parameters:
      value - the object value to serialize.
      Returns:
      a JSON representation of the given object as a String.
    • fromJson

      public static <T> T fromJson(String string, Class<T> type)
      Deserializes the given JSON string into an object of the specified type.
      Type Parameters:
      T - the type of the object to return.
      Parameters:
      string - the JSON string to deserialize.
      type - the class of the target type.
      Returns:
      an object of type T.
    • fromJson

      public static <T> T fromJson(InputStream input, Class<T> type)
      Deserializes JSON from the given InputStream into an object of the specified type.
      Type Parameters:
      T - the type of the object to return.
      Parameters:
      input - the InputStream containing JSON data.
      type - the class of the target type.
      Returns:
      an object of type T.