public final class JSONUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static boolean |
getBoolean(JSONObject jsonObject,
java.lang.String key,
boolean defaultValue)
Gets boolean value bound with specified key.
|
static java.lang.Boolean |
getBooleanBoxed(JSONObject jsonObject,
java.lang.String key) |
static double |
getDouble(JSONObject jsonObject,
java.lang.String key,
double defaultValue)
Gets double value bound with specified key.
|
static int |
getInt(JSONObject jsonObject,
java.lang.String key,
int defaultValue)
Gets int value bound with specified key.
|
static JSONArray |
getJSONArray(JSONObject jsonObject,
java.lang.String key,
JSONArray defaultValue) |
static java.lang.String |
getJSONArrayElement(JSONArray sourceArray,
int index) |
static JSONObject |
getJSONObject(JSONArray sourceObject,
int index) |
static long |
getLong(JSONObject jsonObject,
java.lang.String key,
long defaultValue)
Gets long value bound with specified key.
|
static java.lang.String |
getString(JSONObject jsonObject,
java.lang.String key,
java.lang.String defaultValue)
Gets string value bound with specified key.
|
static java.lang.String |
getStringOrNull(JSONObject jsonObject,
java.lang.String key)
Gets string or null.
|
static java.util.UUID |
getUUID(JSONObject jsonObject,
java.lang.String key,
java.util.UUID defaultValue)
Gets UUID value bound with specified key.
|
static java.util.UUID |
getUUIDOrNull(JSONObject jsonObject,
java.lang.String key)
Gets UUID value bound with specified key or null if the key does not exist.
|
static boolean |
hasJSONKey(JSONObject jsonObject,
java.lang.String key)
Checks whether JSONObject contains specified key with non-null value.
|
static <T> T |
transformOrReturnNull(JSONObject jsonObject,
java.lang.String jsonEntry,
SDKFunction<JSONObject,T> convertFunction)
Transform JSONObject's property accessible under specified entry to desired instance or return null.
|
static <T> T |
transformOrThrow(JSONArray jsonArray,
SDKThrowableFunction<JSONArray,T,java.lang.Exception> transformFunction)
Transform JSONArray to desired type.
|
static <T> T |
transformOrThrow(JSONObject jsonObject,
SDKThrowableFunction<JSONObject,T,java.lang.Exception> transformFunction)
Transform JSONObject to desired type.
|
static <T> java.util.List<T> |
transformToListOrReturnEmpty(JSONObject jsonObject,
java.lang.String tag,
SDKFunction<JSONObject,T> function)
Transform to list or return empty.
|
public static boolean hasJSONKey(JSONObject jsonObject, java.lang.String key)
jsonObject
- the json objectkey
- the keypublic static java.lang.String getString(JSONObject jsonObject, java.lang.String key, java.lang.String defaultValue)
jsonObject
- the json objectkey
- the keydefaultValue
- the default valuepublic static int getInt(JSONObject jsonObject, java.lang.String key, int defaultValue)
jsonObject
- the json objectkey
- the keydefaultValue
- the default valuepublic static long getLong(JSONObject jsonObject, java.lang.String key, long defaultValue)
jsonObject
- the json objectkey
- the keydefaultValue
- the default valuepublic static double getDouble(JSONObject jsonObject, java.lang.String key, double defaultValue)
jsonObject
- the json objectkey
- the keydefaultValue
- the default valuepublic static java.util.UUID getUUID(JSONObject jsonObject, java.lang.String key, java.util.UUID defaultValue)
jsonObject
- the json objectkey
- the keydefaultValue
- the default valuepublic static java.util.UUID getUUIDOrNull(JSONObject jsonObject, java.lang.String key)
jsonObject
- the json objectkey
- the keypublic static java.lang.String getStringOrNull(JSONObject jsonObject, java.lang.String key)
jsonObject
- the json objectkey
- the keypublic static boolean getBoolean(JSONObject jsonObject, java.lang.String key, boolean defaultValue)
jsonObject
- the json objectkey
- the keydefaultValue
- the default valuepublic static java.lang.Boolean getBooleanBoxed(JSONObject jsonObject, java.lang.String key)
public static JSONArray getJSONArray(JSONObject jsonObject, java.lang.String key, JSONArray defaultValue)
public static JSONObject getJSONObject(JSONArray sourceObject, int index)
public static java.lang.String getJSONArrayElement(JSONArray sourceArray, int index)
public static <T> T transformOrThrow(JSONObject jsonObject, SDKThrowableFunction<JSONObject,T,java.lang.Exception> transformFunction)
T
- the type parameterjsonObject
- the json objecttransformFunction
- the throwable functionjava.lang.IllegalStateException
- in case of failurepublic static <T> T transformOrThrow(JSONArray jsonArray, SDKThrowableFunction<JSONArray,T,java.lang.Exception> transformFunction)
T
- the type parameterjsonArray
- the json arraytransformFunction
- the throwable functionjava.lang.IllegalStateException
- in case of failurepublic static <T> java.util.List<T> transformToListOrReturnEmpty(JSONObject jsonObject, java.lang.String tag, SDKFunction<JSONObject,T> function)
T
- the type parameterjsonObject
- the json objecttag
- the tagfunction
- the functionpublic static <T> T transformOrReturnNull(JSONObject jsonObject, java.lang.String jsonEntry, SDKFunction<JSONObject,T> convertFunction)
T
- the type parameterjsonObject
- the json objectjsonEntry
- the json entryconvertFunction
- the convert function