Class JSONObjectToObjectExtensions

java.lang.Object
io.github.astrapi69.json.JSONObjectToObjectExtensions

public final class JSONObjectToObjectExtensions extends Object
The class JSONObjectToObjectExtensions converts json strings to java object and java collections.
  • Method Details

    • toObject

      public static <T> T toObject(org.json.JSONObject jsonObject, Class<T> clazz, com.fasterxml.jackson.databind.ObjectMapper mapper) throws IOException
      Transforms the given json object into a java object
      Type Parameters:
      T - the generic type
      Parameters:
      jsonObject - the json object
      clazz - the clazz of the generic type
      mapper - the object mapper
      Returns:
      the java object
      Throws:
      IOException - Signals that an I/O exception has occurred
    • toObjectList

      public static <T> List<T> toObjectList(org.json.JSONArray jsonArray, Class<T> elementClass) throws IOException
      Transforms the given JSONArray into a java object List.
      Type Parameters:
      T - the generic type
      Parameters:
      jsonArray - the json array the element class of the generic type
      elementClass - the element class
      Returns:
      the list with the java objects
      Throws:
      IOException - Signals that an I/O exception has occurred.