@Component public class JsonHelper extends Object
| Constructor and Description |
|---|
JsonHelper() |
| Modifier and Type | Method and Description |
|---|---|
<T> T |
getKeyValue(JSONObject jsonObject,
Object key,
Class<T> classType)
Gets key value from the specified JSON object.
|
String |
objectToJson(Object object)
Serializes any Java value as JSON output.
|
<T> List<T> |
unmarshallJsonToListOfObjects(Class<T> classType,
String jsonContent)
Deserializes JSON content from given JSON content String to a list of objects.
|
<T> T |
unmarshallJsonToObject(Class<T> classType,
String jsonContent)
Deserializes JSON content from given JSON content String.
|
public <T> T getKeyValue(JSONObject jsonObject,
Object key,
Class<T> classType)
T - the return typejsonObject - the JSON object that contains the key valuekey - the key nameclassType - the class to cast the result topublic String objectToJson(Object object) throws IllegalStateException
object - the Java object to be serializedIllegalStateException - when an I/O error occurspublic <T> List<T> unmarshallJsonToListOfObjects(Class<T> classType, String jsonContent) throws IOException
classType - the class type of the objectjsonContent - the JSON stringIOException - if there is an error in unmarshallingpublic <T> T unmarshallJsonToObject(Class<T> classType, String jsonContent) throws IOException
classType - the class type of the objectjsonContent - the JSON stringIOException - if there is an error in unmarshallingCopyright © 2021. All rights reserved.