java.lang.Object
io.github.astrapi69.json.JsonStringToObjectExtensions
The class
JsonStringToObjectExtensions
converts json strings to java object and java
collections.-
Method Summary
Modifier and TypeMethodDescriptionstatic <K,
V> Map<K, V> toMapObject
(String jsonString, com.fasterxml.jackson.core.type.TypeReference<Map<K, V>> typeReference) Transforms the given json string into a java map objectstatic <K,
V> Map<K, V> toMapObject
(String jsonString, com.fasterxml.jackson.core.type.TypeReference<Map<K, V>> typeReference, com.fasterxml.jackson.databind.ObjectMapper mapper) Transforms the given json string into a java map objectstatic <T> T
toObject
(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
Transforms the given json string into a java object.static <T> T
Transforms the given json string into a java object.static <T> T
Transforms the given json string into a java object.static <T> T
Transforms the given json string into a java object.static <T> Collection<T>
toObjectCollection
(String jsonString, Class<? extends Collection> collectionClass, Class<T> elementClass) Transforms the given json string into a java objectCollection
static <T> List<T>
toObjectList
(String jsonString, Class<T> elementClass) Transforms the given json string into a java objectList
-
Method Details
-
toMapObject
public static <K,V> Map<K,V> toMapObject(String jsonString, com.fasterxml.jackson.core.type.TypeReference<Map<K, V>> typeReference) throws IOExceptionTransforms the given json string into a java map object- Type Parameters:
K
- the generic type of keysV
- the generic type of values- Parameters:
jsonString
- the json stringtypeReference
- the type reference- Returns:
- the t
- Throws:
IOException
- Signals that an I/O exception has occurred
-
toMapObject
public static <K,V> Map<K,V> toMapObject(String jsonString, com.fasterxml.jackson.core.type.TypeReference<Map<K, V>> typeReference, com.fasterxml.jackson.databind.ObjectMapper mapper) throws IOExceptionTransforms the given json string into a java map object- Type Parameters:
K
- the generic type of keysV
- the generic type of values- Parameters:
jsonString
- the json stringtypeReference
- the type referencemapper
- the object mapper- Returns:
- the t
- Throws:
IOException
- Signals that an I/O exception has occurred
-
toObject
Transforms the given json string into a java object.- Type Parameters:
T
- the generic type of the return type- Parameters:
jsonString
- the json stringclazz
- the clazz of the generic type- Returns:
- the object
- Throws:
IOException
- Signals that an I/O exception has occurred.
-
toObject
public static <T> T toObject(String jsonString, Class<T> clazz, boolean newMapper) throws IOException Transforms the given json string into a java object.- Type Parameters:
T
- the generic type of the return type- Parameters:
jsonString
- the json stringclazz
- the clazz of the generic typenewMapper
- 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:
IOException
- Signals that an I/O exception has occurred.
-
toObject
public static <T> T toObject(String jsonString, Class<T> clazz, com.fasterxml.jackson.databind.Module... modules) throws IOException Transforms the given json string into a java object.- Type Parameters:
T
- the generic type of the return type- Parameters:
jsonString
- the json stringclazz
- the clazz of the generic typemodules
- The modules to register for the mapper- Returns:
- the object
- Throws:
IOException
- Signals that an I/O exception has occurred.
-
toObject
public static <T> T toObject(String jsonString, Class<T> clazz, com.fasterxml.jackson.databind.ObjectMapper mapper) throws IOException Transforms the given json string into a java object.- Type Parameters:
T
- the generic type- Parameters:
jsonString
- the json stringclazz
- the clazz of the generic typemapper
- the object mapper- Returns:
- the t
- Throws:
IOException
- Signals that an I/O exception has occurred
-
toObject
public static <T> T toObject(String jsonString, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, com.fasterxml.jackson.databind.ObjectMapper mapper) throws IOException Transforms the given json string into a java object.- Type Parameters:
T
- the generic type- Parameters:
jsonString
- the json stringtypeReference
- the type referencemapper
- the object mapper- Returns:
- the t
- Throws:
IOException
- Signals that an I/O exception has occurred
-
toObjectCollection
public static <T> Collection<T> toObjectCollection(String jsonString, Class<? extends Collection> collectionClass, Class<T> elementClass) throws IOException Transforms the given json string into a java objectCollection
- Type Parameters:
T
- the generic type of the return type- Parameters:
jsonString
- the json stringcollectionClass
- the collection classelementClass
- the element class- Returns:
- the list with the java objects.
- Throws:
IOException
- Signals that an I/O exception has occurred
-
toObjectList
Transforms the given json string into a java objectList
- Type Parameters:
T
- the generic type of the return type- Parameters:
jsonString
- the json stringelementClass
- the element class of the generic type- Returns:
- the list with the java objects
- Throws:
IOException
- Signals that an I/O exception has occurred.
-