Package com.nimbusds.oauth2.sdk.util
Class JSONObjectUtils
java.lang.Object
com.nimbusds.oauth2.sdk.util.JSONObjectUtils
JSON object helper methods for parsing and typed retrieval of member values.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleancontainsKey(net.minidev.json.JSONObject jsonObject, String key) Returnstrueif the JSON object is defined and contains the specified key.static booleangetBoolean(net.minidev.json.JSONObject o, String key) Gets a boolean member of a JSON object.static booleangetBoolean(net.minidev.json.JSONObject o, String key, boolean def) Gets a boolean member of a JSON object.static doubleGets a number member of a JSON object asdouble.static doubleGets a number member of a JSON object asdouble.static <T extends Enum<T>>
TGets a string member of a JSON object as an enumerated object.static <T extends Enum<T>>
TGets a string member of a JSON object as an enumerated object.static floatGets a number member of a JSON objectfloat.static floatGets a number member of a JSON objectfloat.static <T> TgetGeneric(net.minidev.json.JSONObject o, String key, Class<T> clazz) Gets a generic member of a JSON object.static intGets an number member of a JSON object asint.static intGets an number member of a JSON object asint.static net.minidev.json.JSONArraygetJSONArray(net.minidev.json.JSONObject o, String key) Gets a JSON array member of a JSON object.static net.minidev.json.JSONArraygetJSONArray(net.minidev.json.JSONObject o, String key, net.minidev.json.JSONArray def) Gets a JSON array member of a JSON object.static net.minidev.json.JSONObjectgetJSONObject(net.minidev.json.JSONObject o, String key) Gets a JSON object member of a JSON object.static net.minidev.json.JSONObjectgetJSONObject(net.minidev.json.JSONObject o, String key, net.minidev.json.JSONObject def) Gets a JSON object member of a JSON object.Gets a list member of a JSON object.Gets a list member of a JSON object.static longGets a number member of a JSON object aslong.static longGets a number member of a JSON object aslong.static NumberGets a number member of a JSON object asjava.lang.Number.static NumberGets a number member of a JSON object asjava.lang.Number.static StringGets a string member of a JSON object.static StringGets a string member of a JSON object.static String[]getStringArray(net.minidev.json.JSONObject o, String key) Gets a string array member of a JSON object.static String[]getStringArray(net.minidev.json.JSONObject o, String key, String[] def) Gets a string array member of a JSON object.getStringList(net.minidev.json.JSONObject o, String key) Gets a string list member of a JSON object.getStringList(net.minidev.json.JSONObject o, String key, List<String> def) Gets a string list member of a JSON object.getStringSet(net.minidev.json.JSONObject o, String key) Gets a string array member of a JSON object as a string set.getStringSet(net.minidev.json.JSONObject o, String key, Set<String> def) Gets a string array member of a JSON object as a string set.static URIGets a string member of a JSON object asjava.net.URI.static URIGets a string member of a JSON object asjava.net.URI.static URLGets a string member of a JSON object asjava.net.URL.static URLGets a string member of a JSON object asjava.net.URL.static net.minidev.json.JSONObjectParses a JSON object.static net.minidev.json.JSONObjectDeprecated.static LinkedHashMap<String,Object> Parses a JSON object while keeping the order of JSON object members.static net.minidev.json.JSONObjecttoJSONObject(com.nimbusds.jose.jwk.JWKSet jwkSet) Returns the JSON object representation of the specified JWK set.static net.minidev.json.JSONObjecttoJSONObject(com.nimbusds.jwt.JWTClaimsSet jwtClaimsSet) Returns the JSON object representation of the specified JWT claims set.
-
Method Details
-
containsKey
Returnstrueif the JSON object is defined and contains the specified key.- Parameters:
jsonObject- The JSON object to check. May benull.key- The key to check. Must not benull.- Returns:
trueif the JSON object is defined and contains the specified key, elsefalse.
-
parse
Parses a JSON object.Specific JSON to Java entity mapping (as per JSON Simple):
- JSON numbers mapped to
java.lang.Number. - JSON integer numbers mapped to
long. - JSON fraction numbers mapped to
double.
- Parameters:
s- The JSON object string to parse. Must not benull.- Returns:
- The JSON object.
- Throws:
ParseException- If the string cannot be parsed to a JSON object.
- JSON numbers mapped to
-
parseKeepingOrder
Parses a JSON object while keeping the order of JSON object members.Specific JSON to Java entity mapping (as per JSON Simple):
- JSON numbers mapped to
java.lang.Number. - JSON integer numbers mapped to
long. - JSON fraction numbers mapped to
double.
- Parameters:
s- The JSON object string to parse. Must not benull.- Returns:
- The JSON object as linked hash map.
- Throws:
ParseException- If the string cannot be parsed to a JSON object.
- JSON numbers mapped to
-
parseJSONObject
@Deprecated public static net.minidev.json.JSONObject parseJSONObject(String s) throws ParseException Deprecated.Useparse(String)instead.- Parameters:
s- The JSON object string to parse. Must not benull.- Returns:
- The JSON object.
- Throws:
ParseException- If the string cannot be parsed to a JSON object.
-
getGeneric
public static <T> T getGeneric(net.minidev.json.JSONObject o, String key, Class<T> clazz) throws ParseException Gets a generic member of a JSON object.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.clazz- The expected class of the JSON object member value. Must not benull.- Returns:
- The JSON object member value.
- Throws:
ParseException- If the value is missing,nullor not of the expected type.
-
getBoolean
Gets a boolean member of a JSON object.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is missing,nullor not of the expected type.
-
getBoolean
public static boolean getBoolean(net.minidev.json.JSONObject o, String key, boolean def) throws ParseException Gets a boolean member of a JSON object.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.def- The default value to return if the key is not present or. the value isnull. May benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is not of the expected type.
-
getInt
Gets an number member of a JSON object asint.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is missing,nullor not of the expected type.
-
getInt
Gets an number member of a JSON object asint.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.def- The default value to return if the key is not present or the value isnull.- Returns:
- The member value.
- Throws:
ParseException- If the value is not of the expected type.
-
getLong
Gets a number member of a JSON object aslong.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is missing,nullor not of the expected type.
-
getLong
public static long getLong(net.minidev.json.JSONObject o, String key, long def) throws ParseException Gets a number member of a JSON object aslong.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.def- The default value to return if the key is not present or the value isnull.- Returns:
- The member value.
- Throws:
ParseException- If the value is not of the expected type.
-
getFloat
Gets a number member of a JSON objectfloat.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is missing,nullor not of the expected type.
-
getFloat
public static float getFloat(net.minidev.json.JSONObject o, String key, float def) throws ParseException Gets a number member of a JSON objectfloat.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.def- The default value to return if the key is not present or the value isnull.- Returns:
- The member value.
- Throws:
ParseException- If the value is not of the expected type.
-
getDouble
Gets a number member of a JSON object asdouble.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is missing,nullor not of the expected type.
-
getDouble
public static double getDouble(net.minidev.json.JSONObject o, String key, double def) throws ParseException Gets a number member of a JSON object asdouble.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.def- The default value to return if the key is not present or the value isnull.- Returns:
- The member value.
- Throws:
ParseException- If the value is not of the expected type.
-
getNumber
Gets a number member of a JSON object asjava.lang.Number.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is missing,nullor not of the expected type.
-
getNumber
public static Number getNumber(net.minidev.json.JSONObject o, String key, Number def) throws ParseException Gets a number member of a JSON object asjava.lang.Number.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.def- The default value to return if the key is not present or the value isnull. May benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is not of the expected type.
-
getString
Gets a string member of a JSON object.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is missing,nullor not of the expected type.
-
getString
public static String getString(net.minidev.json.JSONObject o, String key, String def) throws ParseException Gets a string member of a JSON object.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.def- The default value to return if the key is not present or the value isnull. May benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is not of the expected type.
-
getEnum
public static <T extends Enum<T>> T getEnum(net.minidev.json.JSONObject o, String key, Class<T> enumClass) throws ParseException Gets a string member of a JSON object as an enumerated object.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.enumClass- The enumeration class. Must not benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is missing,nullor not of the expected type.
-
getEnum
public static <T extends Enum<T>> T getEnum(net.minidev.json.JSONObject o, String key, Class<T> enumClass, T def) throws ParseException Gets a string member of a JSON object as an enumerated object.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.enumClass- The enumeration class. Must not benull.def- The default value to return if the key is not present or the value isnull. May benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is not of the expected type.
-
getURI
Gets a string member of a JSON object asjava.net.URI.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is missing,nullor not of the expected type.
-
getURI
Gets a string member of a JSON object asjava.net.URI.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.def- The default value to return if the key is not present or the value isnull. May benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is not of the expected type.
-
getURL
Gets a string member of a JSON object asjava.net.URL.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is missing,nullor not of the expected type.
-
getURL
Gets a string member of a JSON object asjava.net.URL.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.def- The default value to return if the key is not present or the value isnull. May benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is not of the expected type.
-
getJSONArray
public static net.minidev.json.JSONArray getJSONArray(net.minidev.json.JSONObject o, String key) throws ParseException Gets a JSON array member of a JSON object.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is missing,nullor not of the expected type.
-
getJSONArray
public static net.minidev.json.JSONArray getJSONArray(net.minidev.json.JSONObject o, String key, net.minidev.json.JSONArray def) throws ParseException Gets a JSON array member of a JSON object.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.def- The default value to return if the key is not present or the value isnull. May benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is not of the expected type.
-
getList
Gets a list member of a JSON object.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is missing,nullor not of the expected type.
-
getList
public static List<Object> getList(net.minidev.json.JSONObject o, String key, List<Object> def) throws ParseException Gets a list member of a JSON object.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.def- The default value to return if the key is not present or the value isnull. May benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is not of the expected type.
-
getStringArray
public static String[] getStringArray(net.minidev.json.JSONObject o, String key) throws ParseException Gets a string array member of a JSON object.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is missing,nullor not of the expected type.
-
getStringArray
public static String[] getStringArray(net.minidev.json.JSONObject o, String key, String[] def) throws ParseException Gets a string array member of a JSON object.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.def- The default value to return if the key is not present or the value isnull. May benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is not of the expected type.
-
getStringList
public static List<String> getStringList(net.minidev.json.JSONObject o, String key) throws ParseException Gets a string list member of a JSON object.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is missing,nullor not of the expected type.
-
getStringList
public static List<String> getStringList(net.minidev.json.JSONObject o, String key, List<String> def) throws ParseException Gets a string list member of a JSON object.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.def- The default value to return if the key is not present or the value isnull. May benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is not of the expected type.
-
getStringSet
public static Set<String> getStringSet(net.minidev.json.JSONObject o, String key) throws ParseException Gets a string array member of a JSON object as a string set.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is missing,nullor not of the expected type.
-
getStringSet
public static Set<String> getStringSet(net.minidev.json.JSONObject o, String key, Set<String> def) throws ParseException Gets a string array member of a JSON object as a string set.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.def- The default value to return if the key is not present or the value isnull. May benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is not of the expected type.
-
getJSONObject
public static net.minidev.json.JSONObject getJSONObject(net.minidev.json.JSONObject o, String key) throws ParseException Gets a JSON object member of a JSON object.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is missing,nullor not of the expected type.
-
getJSONObject
public static net.minidev.json.JSONObject getJSONObject(net.minidev.json.JSONObject o, String key, net.minidev.json.JSONObject def) throws ParseException Gets a JSON object member of a JSON object.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.def- The default value to return if the key is not present or the value isnull. May benull.- Returns:
- The member value.
- Throws:
ParseException- If the value is not of the expected type.
-
toJSONObject
Returns the JSON object representation of the specified JWT claims set.- Parameters:
jwtClaimsSet- The JWT claims set,nullif not specified.- Returns:
- The JSON object,
nullif not specified.
-
toJSONObject
Returns the JSON object representation of the specified JWK set.- Parameters:
jwkSet- The JWK set,nullif not specified.- Returns:
- The JSON object,
nullif not specified.
-