Package com.nimbusds.jose.util
Class JSONObjectUtils
- java.lang.Object
-
- com.nimbusds.jose.util.JSONObjectUtils
-
public class JSONObjectUtils extends java.lang.ObjectJSON object helper methods.- Version:
- 2022-08-19
- Author:
- Vladimir Dzhuvinov
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static Base64URLgetBase64URL(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key)Gets a string member of a JSON object asBase64URL.static booleangetBoolean(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key)Gets a boolean member of a JSON object.static doublegetDouble(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key)Gets a number member of a JSON object asdouble.static floatgetFloat(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key)Gets a number member of a JSON objectfloat.static intgetInt(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key)Gets an number member of a JSON object asint.static java.util.List<java.lang.Object>getJSONArray(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key)Gets a JSON array member of a JSON object.static java.util.Map<java.lang.String,java.lang.Object>getJSONObject(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key)Gets a JSON object member of a JSON object.static java.util.Map<java.lang.String,java.lang.Object>[]getJSONObjectArray(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key)Gets a JSON objects array member of a JSON object.static longgetLong(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key)Gets a number member of a JSON object aslong.static java.lang.StringgetString(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key)Gets a string member of a JSON object.static java.lang.String[]getStringArray(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key)Gets a string array member of a JSON object.static java.util.List<java.lang.String>getStringList(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key)Gets a string list member of a JSON objectstatic java.net.URIgetURI(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key)Gets a string member of a JSON object asjava.net.URI.static java.util.Map<java.lang.String,java.lang.Object>newJSONObject()Creates a new JSON object (unordered).static java.util.Map<java.lang.String,java.lang.Object>parse(java.lang.String s)Parses a JSON object.static java.util.Map<java.lang.String,java.lang.Object>parse(java.lang.String s, int sizeLimit)Parses a JSON object with the option to limit the input string size.static java.util.Map<java.lang.String,java.lang.Object>parseJSONObject(java.lang.String s)Deprecated.static java.lang.StringtoJSONString(java.util.Map<java.lang.String,?> o)Serialises the specified map to a JSON object using the entity mapping specified inparse(String).
-
-
-
Method Detail
-
parse
public static java.util.Map<java.lang.String,java.lang.Object> parse(java.lang.String s) throws java.text.ParseExceptionParses a JSON object.Specific JSON to Java entity mapping (as per JSON Smart):
- JSON true|false map to
java.lang.Boolean. - JSON numbers map to
java.lang.Number.- JSON integer numbers map to
long. - JSON fraction numbers map to
double.
- JSON integer numbers map to
- JSON strings map to
java.lang.String. - JSON arrays map to
java.util.List<Object>. - JSON objects map to
java.util.Map<String,Object>.
- Parameters:
s- The JSON object string to parse. Must not benull.- Returns:
- The JSON object.
- Throws:
java.text.ParseException- If the string cannot be parsed to a valid JSON object.
- JSON true|false map to
-
parse
public static java.util.Map<java.lang.String,java.lang.Object> parse(java.lang.String s, int sizeLimit) throws java.text.ParseExceptionParses a JSON object with the option to limit the input string size.Specific JSON to Java entity mapping (as per JSON Smart):
- JSON true|false map to
java.lang.Boolean. - JSON numbers map to
java.lang.Number.- JSON integer numbers map to
long. - JSON fraction numbers map to
double.
- JSON integer numbers map to
- JSON strings map to
java.lang.String. - JSON arrays map to
java.util.List<Object>. - JSON objects map to
java.util.Map<String,Object>.
- Parameters:
s- The JSON object string to parse. Must not benull.sizeLimit- The max allowed size of the string to parse. A negative integer means no limit.- Returns:
- The JSON object.
- Throws:
java.text.ParseException- If the string cannot be parsed to a valid JSON object.
- JSON true|false map to
-
parseJSONObject
@Deprecated public static java.util.Map<java.lang.String,java.lang.Object> parseJSONObject(java.lang.String s) throws java.text.ParseExceptionDeprecated.Useparse(String)instead.- Parameters:
s- The JSON object string to parse. Must not benull.- Returns:
- The JSON object.
- Throws:
java.text.ParseException- If the string cannot be parsed to a valid JSON object.
-
getBoolean
public static boolean getBoolean(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key) throws java.text.ParseExceptionGets 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 JSON object member value.
- Throws:
java.text.ParseException- If the member is missing, the value isnullor not of the expected type.
-
getInt
public static int getInt(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key) throws java.text.ParseExceptionGets 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 JSON object member value.
- Throws:
java.text.ParseException- If the member is missing, the value isnullor not of the expected type.
-
getLong
public static long getLong(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key) throws java.text.ParseExceptionGets 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 JSON object member value.
- Throws:
java.text.ParseException- If the member is missing, the value isnullor not of the expected type.
-
getFloat
public static float getFloat(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key) throws java.text.ParseExceptionGets 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 JSON object member value, may be
null. - Throws:
java.text.ParseException- If the member is missing, the value isnullor not of the expected type.
-
getDouble
public static double getDouble(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key) throws java.text.ParseExceptionGets 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 JSON object member value, may be
null. - Throws:
java.text.ParseException- If the member is missing, the value isnullor not of the expected type.
-
getString
public static java.lang.String getString(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key) throws java.text.ParseExceptionGets 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 JSON object member value, may be
null. - Throws:
java.text.ParseException- If the value is not of the expected type.
-
getURI
public static java.net.URI getURI(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key) throws java.text.ParseExceptionGets 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 JSON object member value, may be
null. - Throws:
java.text.ParseException- If the value is not of the expected type.
-
getJSONArray
public static java.util.List<java.lang.Object> getJSONArray(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key) throws java.text.ParseExceptionGets 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 JSON object member value, may be
null. - Throws:
java.text.ParseException- If the value is not of the expected type.
-
getStringArray
public static java.lang.String[] getStringArray(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key) throws java.text.ParseExceptionGets 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 JSON object member value, may be
null. - Throws:
java.text.ParseException- If the value is not of the expected type.
-
getJSONObjectArray
public static java.util.Map<java.lang.String,java.lang.Object>[] getJSONObjectArray(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key) throws java.text.ParseExceptionGets a JSON objects 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 JSON object member value, may be
null. - Throws:
java.text.ParseException- If the value is not of the expected type.
-
getStringList
public static java.util.List<java.lang.String> getStringList(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key) throws java.text.ParseExceptionGets 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 JSON object member value, may be
null. - Throws:
java.text.ParseException- If the value is not of the expected type.
-
getJSONObject
public static java.util.Map<java.lang.String,java.lang.Object> getJSONObject(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key) throws java.text.ParseExceptionGets 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 JSON object member value, may be
null. - Throws:
java.text.ParseException- If the value is not of the expected type.
-
getBase64URL
public static Base64URL getBase64URL(java.util.Map<java.lang.String,java.lang.Object> o, java.lang.String key) throws java.text.ParseException
Gets a string member of a JSON object asBase64URL.- Parameters:
o- The JSON object. Must not benull.key- The JSON object member key. Must not benull.- Returns:
- The JSON object member value, may be
null. - Throws:
java.text.ParseException- If the value is not of the expected type.
-
toJSONString
public static java.lang.String toJSONString(java.util.Map<java.lang.String,?> o)
Serialises the specified map to a JSON object using the entity mapping specified inparse(String).- Parameters:
o- The map. Must not benull.- Returns:
- The JSON object as string.
-
newJSONObject
public static java.util.Map<java.lang.String,java.lang.Object> newJSONObject()
Creates a new JSON object (unordered).- Returns:
- The new empty JSON object.
-
-