Package sg.dex.starfish.util
Class JSON
- java.lang.Object
-
- sg.dex.starfish.util.JSON
-
public class JSON extends Object
Utility class for handling JSON objectsThis class include method to covert json string to map , parse the json string.
- Version:
- 0.5
- Author:
- Mike
-
-
Constructor Summary
Constructors Constructor Description JSON()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
parse(String jsonString)
Converts a string assumed to contain valid JSON value to an Objectstatic Map<String,Object>
toMap(String jsonString)
Converts a string assumed to contain a valid JSON object to a (possibly nested) Map.static String
toPrettyString(Object value)
Converts an object to a pretty-printed JSON string representation suitable for human consumptionstatic String
toString(Object value)
Converts an object to an efficient JSON string representation
-
-
-
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
-
-