Package com.version1.webdriver.utils
Class JsonUtils
java.lang.Object
com.version1.webdriver.utils.JsonUtils
A simple class that helps serialize and deserialize JSON objects in various formats and inputs
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Tstatic <T> TDeserialize a JSON from a File to a given class typestatic <T> TfromFile(InputStream jsonStream, com.fasterxml.jackson.core.type.TypeReference<T> type) static <T> TfromFile(InputStream jsonStream, Class<T> type) Deserialize a JSON from a File to a given class typestatic <T> TDeserialize a JSON from a File to a given class typestatic <T> TfromString(String jsonString, com.fasterxml.jackson.core.type.TypeReference<T> type) Deserialize a JSON from a String to a given class typestatic <T> TfromString(String jsonString, Class<T> type) Deserialize a JSON from a String to a given class typestatic StringSerializes a given object instance into a JSON and returns it as a String
-
Method Details
-
fromString
public static <T> T fromString(String jsonString, com.fasterxml.jackson.core.type.TypeReference<T> type) throws com.fasterxml.jackson.core.JsonProcessingException Deserialize a JSON from a String to a given class type- Type Parameters:
T- generic type- Parameters:
jsonString- json stringtype- target class type or collection- Returns:
- generic class for mapper
- Throws:
com.fasterxml.jackson.core.JsonProcessingException- if JSON cannot be processed
-
fromString
public static <T> T fromString(String jsonString, Class<T> type) throws com.fasterxml.jackson.core.JsonProcessingException Deserialize a JSON from a String to a given class type- Type Parameters:
T- generic type- Parameters:
jsonString- json stringtype- target class type or collection- Returns:
- generic class for mapper
- Throws:
com.fasterxml.jackson.core.JsonProcessingException- if JSON cannot be processed
-
fromFile
Deserialize a JSON from a File to a given class type- Type Parameters:
T- generic type- Parameters:
file- json filetype- target class type or collection- Returns:
- generic class for mapper
- Throws:
IOException- if file cannot be found
-
fromFile
public static <T> T fromFile(File file, com.fasterxml.jackson.core.type.TypeReference<T> type) throws IOException - Type Parameters:
T- generic type- Parameters:
file- json filetype- target class type of collection- Returns:
- generic class for mapper
- Throws:
IOException- if file cannot be found
-
fromFile
public static <T> T fromFile(InputStream jsonStream, com.fasterxml.jackson.core.type.TypeReference<T> type) throws IOException - Type Parameters:
T-- Parameters:
jsonStream-type-- Returns:
- Throws:
IOException
-
fromFile
Deserialize a JSON from a File to a given class type- Type Parameters:
T- generic type- Parameters:
jsonStream- json streamtype- target class type or collection- Returns:
- generic class for mapper
- Throws:
IOException- if file cannot be found
-
fromFile
Deserialize a JSON from a File to a given class type- Type Parameters:
T- generic type- Parameters:
filePath- json file pathtype- target class type or collection- Returns:
- generic class for mapper
- Throws:
IOException- if file cannot be found
-
toString
public static String toString(Object object) throws com.fasterxml.jackson.core.JsonProcessingException Serializes a given object instance into a JSON and returns it as a String- Parameters:
object- json object- Returns:
- String that represents JSON
- Throws:
com.fasterxml.jackson.core.JsonProcessingException- if JSON cannot be parsed
-