Class JSON


  • public class JSON
    extends Object
    Utility class for handling JSON objects

    This class include method to covert json string to map , parse the json string.

    Version:
    0.5
    Author:
    Mike
    • Constructor Detail

      • JSON

        public JSON()
    • Method Detail

      • toString

        public static String toString​(Object value)
        Converts an object to an efficient JSON string representation
        Parameters:
        value - Object to represent as a JSON String
        Returns:
        JSON string representing the value
        Throws:
        RuntimeException - on failure to create JSON from value
      • toPrettyString

        public static String toPrettyString​(Object value)
        Converts an object to a pretty-printed JSON string representation suitable for human consumption
        Parameters:
        value - Object to represent as a JSON String
        Returns:
        JSON string representing the value
      • toMap

        public static Map<String,​Object> toMap​(String jsonString)
        Converts a string assumed to contain a valid JSON object to a (possibly nested) Map. Use in preference to parse(...) if you know the string should contain a map/object.
        Parameters:
        jsonString - A string containing a valid JSON object
        Returns:
        A map representing the JSON object
        Throws:
        Error - on JSON parsing error
      • parse

        public static <T> T parse​(String jsonString)
        Converts a string assumed to contain valid JSON value to an Object
        Type Parameters:
        T - A type parameter for the type of object returned.
        Parameters:
        jsonString - A string containing valid JSON
        Returns:
        T A java object representing the JSON provided
        Throws:
        Error - on JSON parsing error