Package com.nimbusds.oauth2.sdk.util
Class JSONUtils
- java.lang.Object
-
- com.nimbusds.oauth2.sdk.util.JSONUtils
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Object
parseJSON(String s)
Parses a JSON value.static Object
parseJSONKeepingOrder(String s)
Parses a JSON value while keeping the order of JSON object members.static <T> T
to(Object o, Class<T> clazz)
Casts an object.static boolean
toBoolean(Object o)
Casts an object to a boolean.static List<?>
toList(Object o)
Casts an object to a list.static Number
toNumber(Object o)
Casts an object to a number.static String
toString(Object o)
Casts an object to a string.static List<String>
toStringList(Object o)
Casts an object to a list then returns a string list copy of it casting each item to a string.
-
-
-
Method Detail
-
parseJSON
public static Object parseJSON(String s) throws ParseException
Parses a JSON value.- Parameters:
s
- The JSON string to parse. Must not benull
.- Returns:
- The JSON value.
- Throws:
ParseException
- If the string cannot be parsed to a JSON value.
-
parseJSONKeepingOrder
public static Object parseJSONKeepingOrder(String s) throws ParseException
Parses a JSON value while keeping the order of JSON object members.- Parameters:
s
- The JSON string to parse. Must not benull
.- Returns:
- The JSON value.
- Throws:
ParseException
- If the string cannot be parsed to a JSON value.
-
to
public static <T> T to(Object o, Class<T> clazz) throws ParseException
Casts an object.- Parameters:
o
- The object. Must not benull
.clazz
- The expected class of the object. Must not benull
.- Returns:
- The cast object.
- Throws:
ParseException
- If the object is not of the expected type.
-
toBoolean
public static boolean toBoolean(Object o) throws ParseException
Casts an object to a boolean.- Parameters:
o
- The object. Must not benull
.- Returns:
- The boolean value.
- Throws:
ParseException
- If the object is not of the expected type.
-
toNumber
public static Number toNumber(Object o) throws ParseException
Casts an object to a number.- Parameters:
o
- The object. Must not benull
.- Returns:
- The number.
- Throws:
ParseException
- If the object is not of the expected type.
-
toString
public static String toString(Object o) throws ParseException
Casts an object to a string.- Parameters:
o
- The object. Must not benull
.- Returns:
- The string.
- Throws:
ParseException
- If the object is not of the expected type.
-
toList
public static List<?> toList(Object o) throws ParseException
Casts an object to a list.- Parameters:
o
- The object. Must not benull
.- Returns:
- The list.
- Throws:
ParseException
- If the object is not of the expected type.
-
toStringList
public static List<String> toStringList(Object o) throws ParseException
Casts an object to a list then returns a string list copy of it casting each item to a string.- Parameters:
o
- The object. Must not benull
.- Returns:
- The string list.
- Throws:
ParseException
- If the object is not of the expected type.
-
-