- java.lang.Object
-
- zowe.client.sdk.utility.JsonUtils
-
public final class JsonUtils extends Object
Utility class contains helper methods for JSON parse processing.- Version:
- 5.0
- Author:
- Frank Giordano
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.json.simple.JSONObjectparse(String item)This method is a wrapper for JSONParser().parse() call to parse z/OSMF response which may return ZosmfRequestException.static org.json.simple.JSONArrayparseArray(String item)This method is a wrapper for JSONParser().parse() call to parse z/OSMF response which may return ZosmfRequestException.static Map<String,String>parseMap(org.json.simple.JSONObject jsonObject)Convert a JSONObject to aMap<String, String>, converting all values to String.static <T> TparseResponse(String json, Class<T> clazz, String context)Parse a JSON string into a specified POJO type.
-
-
-
Method Detail
-
parse
public static org.json.simple.JSONObject parse(String item) throws ZosmfRequestException
This method is a wrapper for JSONParser().parse() call to parse z/OSMF response which may return ZosmfRequestException.- Parameters:
item- JSON string representation- Returns:
- JSONObject object
- Throws:
ZosmfRequestException- indicates the JSON item from z/OSMF request is invalid for parsing
-
parseArray
public static org.json.simple.JSONArray parseArray(String item) throws ZosmfRequestException
This method is a wrapper for JSONParser().parse() call to parse z/OSMF response which may return ZosmfRequestException.- Parameters:
item- JSON array representation- Returns:
- JSONArray object
- Throws:
ZosmfRequestException- indicates the JSON item from z/OSMF request is invalid for parsing
-
parseResponse
public static <T> T parseResponse(String json, Class<T> clazz, String context) throws ZosmfRequestException
Parse a JSON string into a specified POJO type.- Type Parameters:
T- the type parameter- Parameters:
json- the JSON string to parseclazz- the target class typecontext- the context for logging purposes- Returns:
- deserialized object of type T
- Throws:
ZosmfRequestException- if parsing fails
-
parseMap
public static Map<String,String> parseMap(org.json.simple.JSONObject jsonObject) throws com.fasterxml.jackson.core.JsonProcessingException
Convert a JSONObject to aMap<String, String>, converting all values to String.This method supports JSON values of any type (string, number, boolean, null, etc.) and ensures that all map values are safely represented as strings.
- Parameters:
jsonObject- the JSONObject to convert (must not be null)- Returns:
- a
Map<String, String>with all keys its values as all String values - Throws:
com.fasterxml.jackson.core.JsonProcessingException- if JSON parsing fails
-
-