Package uk.co.evoco.webdriver.utils
Class JsonUtils
java.lang.Object
uk.co.evoco.webdriver.utils.JsonUtils
public final class JsonUtils
extends java.lang.Object
A simple class that helps serialize and deserialize JSON objects in various formats and inputs
-
Constructor Summary
Constructors Constructor Description JsonUtils() -
Method Summary
Modifier and Type Method Description static <T> TfromFile(java.io.File file, com.fasterxml.jackson.core.type.TypeReference<T> type)static <T> TfromFile(java.io.File file, java.lang.Class<T> type)Deserialize a JSON from a File to a given class typestatic <T> TfromFile(java.io.InputStream jsonStream, java.lang.Class<T> type)Deserialize a JSON from a File to a given class typestatic <T> TfromFile(java.lang.String filePath, java.lang.Class<T> type)Deserialize a JSON from a File to a given class typestatic <T> TfromString(java.lang.String jsonString, com.fasterxml.jackson.core.type.TypeReference<T> type)Deserialize a JSON from a String to a given class typestatic <T> TfromString(java.lang.String jsonString, java.lang.Class<T> type)Deserialize a JSON from a String to a given class typestatic java.lang.StringtoString(java.lang.Object object)Serializes a given object instance into a JSON and returns it as a String
-
Constructor Details
-
JsonUtils
public JsonUtils()
-
-
Method Details
-
fromString
public static <T> T fromString(java.lang.String jsonString, com.fasterxml.jackson.core.type.TypeReference<T> type) throws com.fasterxml.jackson.core.JsonProcessingExceptionDeserialize 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(java.lang.String jsonString, java.lang.Class<T> type) throws com.fasterxml.jackson.core.JsonProcessingExceptionDeserialize 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
public static <T> T fromFile(java.io.File file, java.lang.Class<T> type) throws java.io.IOExceptionDeserialize 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:
java.io.IOException- if file cannot be found
-
fromFile
public static <T> T fromFile(java.io.File file, com.fasterxml.jackson.core.type.TypeReference<T> type) throws java.io.IOException- Type Parameters:
T- generic type- Parameters:
file- json filetype- target class type of collection- Returns:
- generic class for mapper
- Throws:
java.io.IOException- if file cannot be found
-
fromFile
public static <T> T fromFile(java.io.InputStream jsonStream, java.lang.Class<T> type) throws java.io.IOExceptionDeserialize 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:
java.io.IOException- if file cannot be found
-
fromFile
public static <T> T fromFile(java.lang.String filePath, java.lang.Class<T> type) throws java.io.IOExceptionDeserialize 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:
java.io.IOException- if file cannot be found
-
toString
public static java.lang.String toString(java.lang.Object object) throws com.fasterxml.jackson.core.JsonProcessingExceptionSerializes 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
-