@ThreadSafe public final class JsonUtils extends Object
JSONObject
and avoid its bugs.Modifier and Type | Method and Description |
---|---|
static MonetaryValue |
getMonetaryValue(JSONObject json,
String key)
Gets a required
MonetaryValue object from the JSON at the key passed or throws a
JSONException if it's missing. |
static Set<Integer> |
optIntegerSet(JSONObject json,
String key)
|
static Long |
optLongNullable(JSONObject json,
String key)
Helper method that gets an optional nullable
Long value from the JSONObject . |
static MonetaryValue |
optMonetaryValue(JSONObject json,
String key)
Gets an optional
MonetaryValue object from the JSON at the key passed. |
static String |
optString(JSONObject json,
String key)
Helper method that doesn't return some fake version of null if the string is null, it returns
null.
|
static Set<String> |
optStringSet(JSONObject json,
String key)
|
public static Long optLongNullable(JSONObject json, String key)
Long
value from the JSONObject
.json
- the JSONObject
.key
- the key in json
.Long
mapping for key
in json
or null
if no mapping
exists.public static String optString(JSONObject json, String key)
json
- the JSONObject
.key
- the key in json
.String
mapping for key
in json
or null
if no mapping
exists.public static Set<Integer> optIntegerSet(JSONObject json, String key) throws JSONException
json
- the object to read from.key
- the key in json
.key
or
null
if either the key is not present or is set to null
.JSONException
- if the array contents aren't integers.public static Set<String> optStringSet(JSONObject json, String key) throws JSONException
json
- the object to read from.key
- the key in json
.key
or
null
if either the key is not present or is set to null
.JSONException
- if the array contents aren't strings.public static MonetaryValue optMonetaryValue(JSONObject json, String key) throws JSONException
MonetaryValue
object from the JSON at the key passed.json
- the JSONObject
to get the MonetaryValue
from.key
- the key in the JSONObject
to get the MonetaryValue
from.MonetaryValue
from the parsed long or null.JSONException
- if the parsing fails.public static MonetaryValue getMonetaryValue(JSONObject json, String key) throws JSONException
MonetaryValue
object from the JSON at the key passed or throws a
JSONException
if it's missing.json
- the JSONObject
to get the MonetaryValue
from.key
- the key in the JSONObject
to get the MonetaryValue
from.MonetaryValue
from the parsed long.JSONException
- if the parsing fails.