Class JsonStringToObjectExtensions


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

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <K,​V>
      java.util.Map<K,​V>
      toMapObject​(java.lang.String jsonString, com.fasterxml.jackson.core.type.TypeReference<java.util.Map<K,​V>> typeReference)
      Transforms the given json string into a java map object
      static <K,​V>
      java.util.Map<K,​V>
      toMapObject​(java.lang.String jsonString, com.fasterxml.jackson.core.type.TypeReference<java.util.Map<K,​V>> typeReference, com.fasterxml.jackson.databind.ObjectMapper mapper)
      Transforms the given json string into a java map object
      static <T> T toObject​(java.lang.String jsonString, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, com.fasterxml.jackson.databind.ObjectMapper mapper)
      Transforms the given json string into a java object.
      static <T> T toObject​(java.lang.String jsonString, java.lang.Class<T> clazz)
      Transforms the given json string into a java object.
      static <T> T toObject​(java.lang.String jsonString, java.lang.Class<T> clazz, boolean newMapper)
      Transforms the given json string into a java object.
      static <T> T toObject​(java.lang.String jsonString, java.lang.Class<T> clazz, com.fasterxml.jackson.databind.Module... modules)
      Transforms the given json string into a java object.
      static <T> T toObject​(java.lang.String jsonString, java.lang.Class<T> clazz, com.fasterxml.jackson.databind.ObjectMapper mapper)
      Transforms the given json string into a java object.
      static <T> java.util.Collection<T> toObjectCollection​(java.lang.String jsonString, java.lang.Class<? extends java.util.Collection> collectionClass, java.lang.Class<T> elementClass)
      Transforms the given json string into a java object Collection
      static <T> java.util.List<T> toObjectList​(java.lang.String jsonString, java.lang.Class<T> elementClass)
      Transforms the given json string into a java object List
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • toMapObject

        public static <K,​V> java.util.Map<K,​V> toMapObject​(java.lang.String jsonString,
                                                                       com.fasterxml.jackson.core.type.TypeReference<java.util.Map<K,​V>> typeReference)
                                                                throws java.io.IOException
        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
        typeReference - the type reference
        Returns:
        the t
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred
      • toMapObject

        public static <K,​V> java.util.Map<K,​V> toMapObject​(java.lang.String jsonString,
                                                                       com.fasterxml.jackson.core.type.TypeReference<java.util.Map<K,​V>> typeReference,
                                                                       com.fasterxml.jackson.databind.ObjectMapper mapper)
                                                                throws java.io.IOException
        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
        typeReference - the type reference
        mapper - the object mapper
        Returns:
        the t
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred
      • toObject

        public static <T> T toObject​(java.lang.String jsonString,
                                     java.lang.Class<T> clazz)
                              throws java.io.IOException
        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
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • toObject

        public static <T> T toObject​(java.lang.String jsonString,
                                     java.lang.Class<T> clazz,
                                     boolean newMapper)
                              throws java.io.IOException
        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
        newMapper - flag that indicates if a new ObjectMapper should be created. if true a new ObjectMapper will be created otherwise the ObjectMapper from this class will be returned.
        Returns:
        the object
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • toObject

        public static <T> T toObject​(java.lang.String jsonString,
                                     java.lang.Class<T> clazz,
                                     com.fasterxml.jackson.databind.Module... modules)
                              throws java.io.IOException
        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
        modules - The modules to register for the mapper
        Returns:
        the object
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • toObject

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

        public static <T> T toObject​(java.lang.String jsonString,
                                     com.fasterxml.jackson.core.type.TypeReference<T> typeReference,
                                     com.fasterxml.jackson.databind.ObjectMapper mapper)
                              throws java.io.IOException
        Transforms the given json string into a java object.
        Type Parameters:
        T - the generic type
        Parameters:
        jsonString - the json string
        typeReference - the type reference
        mapper - the object mapper
        Returns:
        the t
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred
      • toObjectCollection

        public static <T> java.util.Collection<T> toObjectCollection​(java.lang.String jsonString,
                                                                     java.lang.Class<? extends java.util.Collection> collectionClass,
                                                                     java.lang.Class<T> elementClass)
                                                              throws java.io.IOException
        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.
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred
      • toObjectList

        public static <T> java.util.List<T> toObjectList​(java.lang.String jsonString,
                                                         java.lang.Class<T> elementClass)
                                                  throws java.io.IOException
        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
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.