Class JsonStringToObjectExtensions

java.lang.Object
io.github.astrapi69.gson.JsonStringToObjectExtensions

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

    • toMapObject

      public static <K, V> Map<K,V> toMapObject(String jsonString, Class<K> keyType, Class<V> valueType)
      Transforms the given json string into a java map object
      Type Parameters:
      K - the generic type of keys
      V - the generic type of values
      Parameters:
      jsonString - the json string
      keyType - the class type of the key
      valueType - the class type of the value
      Returns:
      the map
    • toMapObject

      public static <K, V> Map<K,V> toMapObject(String jsonString, Class<K> keyType, Class<V> valueType, com.google.gson.Gson gson)
      Transforms the given json string into a java map object
      Type Parameters:
      K - the generic type of keys
      V - the generic type of values
      Parameters:
      jsonString - the json string
      keyType - the class type of the key
      valueType - the class type of the value
      gson - the gson object
      Returns:
      the map
    • toObject

      public static <T> T toObject(String jsonString, Class<T> clazz)
      Transforms the given json string into a java object.
      Type Parameters:
      T - the generic type of the return type
      Parameters:
      jsonString - the json string
      clazz - the clazz of the generic type
      Returns:
      the object
    • toObject

      public static <T> T toObject(String jsonString, Class<T> clazz, com.google.gson.Gson gson)
      Transforms the given json string into a java object.
      Type Parameters:
      T - the generic type of the return type
      Parameters:
      jsonString - the json string
      clazz - the clazz of the generic type
      gson - the gson object
      Returns:
      the object
    • toObjectCollection

      public static <T> Collection<T> toObjectCollection(String jsonString, Class<? extends Collection> collectionClass, Class<T> elementClass)
      Transforms the given json string into a java object Collection
      Type Parameters:
      T - the generic type of the return type
      Parameters:
      jsonString - the json string
      collectionClass - the collection class
      elementClass - the element class
      Returns:
      the list with the java objects.
    • toObjectCollection

      public static <T> Collection<T> toObjectCollection(String jsonString, Class<? extends Collection> collectionClass, Class<T> elementClass, com.google.gson.Gson gson)
      Transforms the given json string into a java object Collection
      Type Parameters:
      T - the generic type of the return type
      Parameters:
      jsonString - the json string
      collectionClass - the collection class
      elementClass - the element class
      gson - the gson object
      Returns:
      the list with the java objects
    • toObjectList

      public static <T> List<T> toObjectList(String jsonString, Class<T> elementClass)
      Transforms the given json string into a java object List
      Type Parameters:
      T - the generic type of the return type
      Parameters:
      jsonString - the json string
      elementClass - the element class of the generic type
      Returns:
      the list with the java objects