Package tripleplay.util
Class JsonUtil
java.lang.Object
tripleplay.util.JsonUtil
Facilities for parsing JSON data
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Json.Array
getArray
(Json.Object json, String key, Json.Array defaultVal) static boolean
getBoolean
(Json.Object json, String key, boolean defaultVal) static <T extends Enum<T>>
TgetEnum
(Json.Object json, String key, Class<T> enumType, T defaultVal) static float
getFloat
(Json.Object json, String key, float defaultVal) static int
getInt
(Json.Object json, String key, int defaultVal) static double
getNumber
(Json.Object json, String key, double defaultVal) static Json.Object
getObject
(Json.Object json, String key, Json.Object defaultVal) static String
getString
(Json.Object json, String key, String defaultVal) static Json.Array
requireArray
(Json.Object json, String key) static boolean
requireBoolean
(Json.Object json, String key) static <T extends Enum<T>>
TrequireEnum
(Json.Object json, String key, Class<T> enumType) static float
requireFloat
(Json.Object json, String key) static int
requireInt
(Json.Object json, String key) static double
requireNumber
(Json.Object json, String key) static Json.Object
requireObject
(Json.Object json, String key) static String
requireString
(Json.Object json, String key) static String
toString
(Platform plat, Json.Object json, boolean verbose)
-
Constructor Details
-
JsonUtil
public JsonUtil()
-
-
Method Details
-
getEnum
public static <T extends Enum<T>> T getEnum(Json.Object json, String key, Class<T> enumType, T defaultVal) - Returns:
- the Enum whose name corresponds to string for the given key, or
defaultVal
if the key doesn't exist.
-
requireEnum
- Returns:
- the Enum whose name corresponds to string for the given key. Throws a RuntimeException if the key doesn't exist.
-
getBoolean
- Returns:
- the boolean value at the given key, or
defaultVal
if the key doesn't exist.
-
requireBoolean
- Returns:
- the boolean value at the given key.
- Throws:
RuntimeException
- if the key doesn't exist.
-
getNumber
- Returns:
- the double value at the given key, or
defaultVal
if the key doesn't exist.
-
requireNumber
- Returns:
- the double value at the given key.
- Throws:
RuntimeException
- if the key doesn't exist.
-
getFloat
- Returns:
- the float value at the given key, or
defaultVal
if the key doesn't exist.
-
requireFloat
- Returns:
- the float value at the given key.
- Throws:
RuntimeException
- if the key doesn't exist.
-
getInt
- Returns:
- the int value at the given key, or
defaultVal
if the key doesn't exist.
-
requireInt
- Returns:
- the int value at the given key.
- Throws:
RuntimeException
- if the key doesn't exist.
-
getString
- Returns:
- the String value at the given key, or
defaultVal
if the key doesn't exist.
-
requireString
- Returns:
- the String value at the given key.
- Throws:
RuntimeException
- if the key doesn't exist.
-
getObject
- Returns:
- the Json.Object value at the given key, or
defaultVal
if the key doesn't exist.
-
requireObject
- Returns:
- the Json.Object at the given key.
- Throws:
RuntimeException
- if the key doesn't exist.
-
getArray
- Returns:
- the Json.Object value at the given key, or
defaultVal
if the key doesn't exist.
-
requireArray
- Returns:
- the Json.Array at the given key.
- Throws:
RuntimeException
- if the key doesn't exist.
-
toString
- Returns:
- a String representation of the given Json
-