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