Package io.mosip.kernel.core.util
Class JsonUtils
- java.lang.Object
-
- io.mosip.kernel.core.util.JsonUtils
-
public class JsonUtils extends Object
This class contains methods used for operations on JSON type data- Since:
- 1.0.0
- Author:
- Sidhant Agarwal
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringjavaObjectToJsonString(Object className)This function converts the java object and returns a JSON Stringstatic List<Object>jsonStringToJavaList(String jsonArray)This method converts a JSON String containing multiple JSON and stores them in a java liststatic Map<String,Object>jsonStringToJavaMap(String jsonString)This method converts a JSON String containing multiple JSON and stores them in a java Mapstatic ObjectjsonStringToJavaObject(Class<?> className, String jsonString)This method converts the JSON String input and maps it to the java objectstatic StringjsonToJacksonJson(String jsonString, String key)This function returns the value associated with the label of the input JSON
-
-
-
Method Detail
-
javaObjectToJsonString
public static String javaObjectToJsonString(Object className) throws JsonProcessingException
This function converts the java object and returns a JSON String- Parameters:
className- object of the class to be converted to JSON File- Returns:
- generated JSON String
- Throws:
JsonProcessingException- when JSON is not properly processed
-
jsonStringToJavaObject
public static Object jsonStringToJavaObject(Class<?> className, String jsonString) throws JsonParseException, JsonMappingException, IOException
This method converts the JSON String input and maps it to the java object- Parameters:
className- class name to which the JSON String is to be mappedjsonString- input JSON String(always in double quotes) (eg."{color=Black, type=FIAT}")- Returns:
- class object with the JSON string parsed to object
- Throws:
JsonParseException- when JSON is not properly parsedJsonMappingException- when JSON is not properly mappedIOException- when location is not found
-
jsonToJacksonJson
public static String jsonToJacksonJson(String jsonString, String key) throws IOException
This function returns the value associated with the label of the input JSON- Parameters:
jsonString- input JSON String(always in double quotes) (eg."{color=Black, type=FIAT}")key- label of the JSON String whose value is to be retrieved- Returns:
- value of the corresponding key input
- Throws:
IOException- when file is not found
-
jsonStringToJavaList
public static List<Object> jsonStringToJavaList(String jsonArray) throws JsonParseException, JsonMappingException, IOException
This method converts a JSON String containing multiple JSON and stores them in a java list- Parameters:
jsonArray- input String containing array of JSON string(always in double quotes) (eg."[{color=Black, type=BMW}, {color=Red, type=FIAT}]")- Returns:
- list of JSON string
- Throws:
JsonParseException- when JSON is not properly parsedJsonMappingException- when JSON is not properly mappedIOException- when file is not found
-
jsonStringToJavaMap
public static Map<String,Object> jsonStringToJavaMap(String jsonString) throws JsonParseException, JsonMappingException, IOException
This method converts a JSON String containing multiple JSON and stores them in a java Map- Parameters:
jsonString- input String containing array of JSON string(always in double quotes) (eg."[{color=Black, type=BMW}, {color=Red, type=FIAT}]")- Returns:
- java map containing JSON inputs
- Throws:
JsonParseException- when JSON is not properly parsedJsonMappingException- when JSON is not properly mappedIOException- when file is not found
-
-