Package com.nimbusds.jose.util
Class JSONObjectUtils
java.lang.Object
com.nimbusds.jose.util.JSONObjectUtils
JSON object helper methods.
- Version:
- 2024-11-14
- Author:
- Vladimir Dzhuvinov
-
Method Summary
Modifier and TypeMethodDescriptionstatic Base64URLgetBase64URL(Map<String, Object> o, String name) Gets a string member of a JSON object asBase64URL.static booleangetBoolean(Map<String, Object> o, String name) Gets a boolean member of a JSON object.static doubleGets a number member of a JSON object asdouble.static DategetEpochSecondAsDate(Map<String, Object> o, String name) Gets a number member of a JSON object as aDateexpressed in seconds since the Unix epoch.static floatGets a number member of a JSON objectfloat.static intGets a number member of a JSON object asint.getJSONArray(Map<String, Object> o, String name) Gets a JSON array member of a JSON object.getJSONObject(Map<String, Object> o, String name) Gets a JSON object member of a JSON object.getJSONObjectArray(Map<String, Object> o, String name) Gets a JSON objects array member of a JSON object.static longGets a number member of a JSON object aslong.static StringGets a string member of a JSON object.static String[]getStringArray(Map<String, Object> o, String name) Gets a string array member of a JSON object.getStringList(Map<String, Object> o, String name) Gets a string list member of a JSON objectstatic URIGets a string member of a JSON object asjava.net.URI.Creates a new JSON object (unordered).Parses a JSON object.Parses a JSON object with the option to limit the input string size.Deprecated.static StringtoJSONString(Map<String, ?> o) Serialises the specified map to a JSON object using the entity mapping specified inparse(String).
-
Method Details
-
parse
Parses 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:
ParseException- If the string cannot be parsed to a valid JSON object.
- JSON true|false map to
-
parse
Parses 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:
ParseException- If the string cannot be parsed to a valid JSON object.
- JSON true|false map to
-
parseJSONObject
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 valid JSON object.
-
getBoolean
Gets a boolean member of a JSON object.- Parameters:
o- The JSON object. Must not benull.name- The JSON object member name. Must not benull.- Returns:
- The JSON object member value.
- Throws:
ParseException- If the member is missing, the value isnullor not of the expected type.
-
getInt
Gets a number member of a JSON object asint.- Parameters:
o- The JSON object. Must not benull.name- The JSON object member name. Must not benull.- Returns:
- The JSON object member value.
- Throws:
ParseException- If the member is missing, the value isnullor not of the expected type.
-
getLong
Gets a number member of a JSON object aslong.- Parameters:
o- The JSON object. Must not benull.name- The JSON object member name. Must not benull.- Returns:
- The JSON object member value.
- Throws:
ParseException- If the member is missing, the value isnullor not of the expected type.
-
getFloat
Gets a number member of a JSON objectfloat.- Parameters:
o- The JSON object. Must not benull.name- The JSON object member name. Must not benull.- Returns:
- The JSON object member value, may be
null. - Throws:
ParseException- If the member is missing, the value isnullor not of the expected type.
-
getDouble
Gets a number member of a JSON object asdouble.- Parameters:
o- The JSON object. Must not benull.name- The JSON object member name. Must not benull.- Returns:
- The JSON object member value, may be
null. - Throws:
ParseException- If the member is missing, the value isnullor not of the expected type.
-
getString
Gets a string member of a JSON object.- Parameters:
o- The JSON object. Must not benull.name- The JSON object member name. Must not benull.- Returns:
- The JSON object member value, may be
null. - 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.name- The JSON object member name. Must not benull.- Returns:
- The JSON object member value, may be
null. - Throws:
ParseException- If the value is not of the expected type.
-
getJSONArray
Gets a JSON array member of a JSON object.- Parameters:
o- The JSON object. Must not benull.name- The JSON object member name. Must not benull.- Returns:
- The JSON object member value, may be
null. - Throws:
ParseException- If the value is not of the expected type.
-
getStringArray
Gets a string array member of a JSON object.- Parameters:
o- The JSON object. Must not benull.name- The JSON object member name. Must not benull.- Returns:
- The JSON object member value, may be
null. - Throws:
ParseException- If the value is not of the expected type.
-
getJSONObjectArray
public static Map<String,Object>[] getJSONObjectArray(Map<String, Object> o, String name) throws ParseExceptionGets a JSON objects array member of a JSON object.- Parameters:
o- The JSON object. Must not benull.name- The JSON object member name. Must not benull.- Returns:
- The JSON object member value, may be
null. - Throws:
ParseException- If the value is not of the expected type.
-
getStringList
Gets a string list member of a JSON object- Parameters:
o- The JSON object. Must not benull.name- The JSON object member name. Must not benull.- Returns:
- The JSON object member value, may be
null. - Throws:
ParseException- If the value is not of the expected type.
-
getJSONObject
public static Map<String,Object> getJSONObject(Map<String, Object> o, String name) throws ParseExceptionGets a JSON object member of a JSON object.- Parameters:
o- The JSON object. Must not benull.name- The JSON object member name. Must not benull.- Returns:
- The JSON object member value, may be
null. - Throws:
ParseException- If the value is not of the expected type.
-
getBase64URL
Gets a string member of a JSON object asBase64URL.- Parameters:
o- The JSON object. Must not benull.name- The JSON object member name. Must not benull.- Returns:
- The JSON object member value, may be
null. - Throws:
ParseException- If the value is not of the expected type.
-
getEpochSecondAsDate
Gets a number member of a JSON object as aDateexpressed in seconds since the Unix epoch.- Parameters:
o- The JSON object. Must not benull.name- The JSON object member name. Must not benull.- Returns:
- The JSON object member value, may be
null. - Throws:
ParseException- If the value is not of the expected type.
-
toJSONString
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
Creates a new JSON object (unordered).- Returns:
- The new empty JSON object.
-