Package io.mosip.mimoto.util
Class JsonUtil
- java.lang.Object
-
- io.mosip.mimoto.util.JsonUtil
-
public class JsonUtil extends Object
This class provides JSON utilites.- Since:
- 0.0.1
- Author:
- Pranav Kumar
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.json.simple.JSONArraygetJSONArray(org.json.simple.JSONObject jsonObject, Object key)This method returns JSONArray from JSONObject.static org.json.simple.JSONObjectgetJSONObject(org.json.simple.JSONObject jsonObject, Object key)This method returns the Json Object as value from identity.json object(JSONObject).static org.json.simple.JSONObjectgetJSONObjectFromArray(org.json.simple.JSONArray jsonObject, int key)Iterates the JSONArray and returns JSONObject for given index.static <T> TgetJSONValue(org.json.simple.JSONObject jsonObject, String key)Gets the JSON value.static JsonValue[]getJsonValues(org.json.simple.JSONObject demographicIdentity, Object identityKey)Gets the json values.static ObjectinputStreamtoJavaObject(InputStream stream, Class<?> clazz)This method converts InputStream to JavaObject.static <T> T[]mapJsonNodeToJavaObject(Class<? extends Object> genericType, org.json.simple.JSONArray demographicJsonNode)Map json node to java object.static StringobjectMapperObjectToJson(Object obj)static <T> TobjectMapperReadValue(String jsonString, Class<?> clazz)Object mapper read value.static <T> TreadValue(String jsonString, Class<?> clazz)Object mapper read value.static StringwriteValueAsString(Object obj)
-
-
-
Method Detail
-
inputStreamtoJavaObject
public static Object inputStreamtoJavaObject(InputStream stream, Class<?> clazz) throws UnsupportedEncodingException
This method converts InputStream to JavaObject.- Parameters:
stream- The stream that needs to be convertedclazz- The class to which conversion is required- Returns:
- The converted Java object
- Throws:
UnsupportedEncodingException- the unsupported encoding exceptioncom.google.gson.JsonSyntaxException- the json syntax exceptioncom.google.gson.JsonIOException- the json IO exception
-
getJSONObject
public static org.json.simple.JSONObject getJSONObject(org.json.simple.JSONObject jsonObject, Object key)This method returns the Json Object as value from identity.json object(JSONObject). jsonObject -> then identity demographic json object key -> demographic json label name EX:- demographicIdentity : { "identity" : { "fullName" : [ { "language" : "eng", "value" : "Taleev Aalam" }, { "language": "ara", "value" : "Taleev Aalam" } ] } method call :- getJSONObject(demographicIdentity,identity)- Parameters:
jsonObject- the json objectkey- the key- Returns:
- the JSON object
-
getJSONArray
public static org.json.simple.JSONArray getJSONArray(org.json.simple.JSONObject jsonObject, Object key)This method returns JSONArray from JSONObject. argument 'jsonObject' -> demographic identity json as JSONObject. argument key -> label name of demographic identity json. Ex:- "identity" : { "fullName" : [ { "language" : "eng", "value" : "Taleev Aalam" }, { "language" : "ara", "value" : "Taleev Aalam" } ] }- Parameters:
jsonObject- the json objectkey- the key- Returns:
- the JSON array
-
writeValueAsString
public static String writeValueAsString(Object obj) throws IOException
- Throws:
IOException
-
readValue
public static <T> T readValue(String jsonString, Class<?> clazz) throws IOException
Object mapper read value. This method maps the jsonString to particular type- Type Parameters:
T- the generic type- Parameters:
jsonString- the json stringclazz- the clazz- Returns:
- the t
- Throws:
com.fasterxml.jackson.core.JsonParseException- the json parse exceptioncom.fasterxml.jackson.databind.JsonMappingException- the json mapping exceptionIOException- Signals that an I/O exception has occurred.
-
getJSONValue
public static <T> T getJSONValue(org.json.simple.JSONObject jsonObject, String key)Gets the JSON value.- Type Parameters:
T- the generic type- Parameters:
jsonObject- the json objectkey- the key- Returns:
- the JSON value
-
getJSONObjectFromArray
public static org.json.simple.JSONObject getJSONObjectFromArray(org.json.simple.JSONArray jsonObject, int key)Iterates the JSONArray and returns JSONObject for given index.- Parameters:
jsonObject- the json objectkey- the key- Returns:
- the JSON object
-
objectMapperReadValue
public static <T> T objectMapperReadValue(String jsonString, Class<?> clazz) throws IOException
Object mapper read value. This method maps the jsonString to particular type- Type Parameters:
T- the generic type- Parameters:
jsonString- the json stringclazz- the clazz- Returns:
- the t
- Throws:
com.fasterxml.jackson.core.JsonParseException- the json parse exceptioncom.fasterxml.jackson.databind.JsonMappingException- the json mapping exceptionIOException- Signals that an I/O exception has occurred.
-
getJsonValues
public static JsonValue[] getJsonValues(org.json.simple.JSONObject demographicIdentity, Object identityKey)
Gets the json values. Returns JsonValue[] java array for the particular key in demographic json.- Parameters:
identityKey- the identity key- Returns:
- the json values
-
mapJsonNodeToJavaObject
public static <T> T[] mapJsonNodeToJavaObject(Class<? extends Object> genericType, org.json.simple.JSONArray demographicJsonNode)
Map json node to java object.- Type Parameters:
T- the generic type- Parameters:
genericType- the generic typedemographicJsonNode- the demographic json node- Returns:
- the t[]
-
objectMapperObjectToJson
public static String objectMapperObjectToJson(Object obj) throws IOException
- Throws:
IOException
-
-