java.lang.Object
io.github.astrapi69.json.JSONObjectToObjectExtensions
The class
JSONObjectToObjectExtensions converts json strings to java object and java
collections.-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TtoObject(org.json.JSONObject jsonObject, Class<T> clazz, com.fasterxml.jackson.databind.ObjectMapper mapper) Transforms the given json object into a java objectstatic <T> List<T>toObjectList(org.json.JSONArray jsonArray, Class<T> elementClass) Transforms the givenJSONArrayinto a java objectList.
-
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 objectclazz- the clazz of the generic typemapper- 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 givenJSONArrayinto a java objectList.- Type Parameters:
T- the generic type- Parameters:
jsonArray- the json array the element class of the generic typeelementClass- the element class- Returns:
- the list with the java objects
- Throws:
IOException- Signals that an I/O exception has occurred.
-