Class JsonUtils


  • public final class JsonUtils
    extends Object
    Utility class contains helper methods for JSON parse processing.
    Version:
    5.0
    Author:
    Frank Giordano
    • 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 parse
        clazz - the target class type
        context - 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 a Map<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