Package com.sap.cloud.security.json
Interface JsonObject
- All Superinterfaces:
Serializable
Interface used to expose JSON data.
-
Method Summary
Modifier and TypeMethodDescriptionReturns the json object as a json string.boolean
getAsInstant
(String name) Returns anInstant
identified by the given propertyname
.<T> List<T>
Parses the json object for the given propertyname
and returns a list of typeJsonObject
.Returns aLong
identified by the given propertyname
.getAsString
(String name) Returns the string identified by the given propertyname
.getAsStringList
(String name) Parses the json object for the given propertyname
and returns a String list.getJsonObject
(String name) Returns a nested JSON object as @{link JsonObject} instance.getJsonObjects
(String name) Returns a nested array of JSON objects as list ofJsonObject
instances.Returns a key-value map of the JSON properties.boolean
isEmpty()
Method to check if the underlying json object is empty.
-
Method Details
-
contains
- Parameters:
name
- the name of the property.- Returns:
- true if the json object contains the given property.
-
isEmpty
boolean isEmpty()Method to check if the underlying json object is empty.- Returns:
- true if the jsonObject is empty.
-
getAsList
Parses the json object for the given propertyname
and returns a list of typeJsonObject
. If the property with the given name is not found, an empty list is returned.- Type Parameters:
T
- the type of the list elements.- Parameters:
name
- the property inside this json object which contains a list as values of typeJsonObject
.type
- type parameter for generic typeJsonObject
.- Returns:
- the list of type
JsonObject
. - Throws:
JsonParsingException
- if the json object with the given key is not a list or list elements are not of typeJsonObject
.
-
getAsStringList
Parses the json object for the given propertyname
and returns a String list. If the property with the given name is not found, an empty list is returned.For example
"aud" : "single-value"
or"aud" : ["value-1", "value-2"]
- Parameters:
name
- the property inside this json object which contains a String list.- Returns:
- the String list.
- Throws:
JsonParsingException
- if the json object with the given key is not a String array or of type String.- See Also:
-
getAsString
Returns the string identified by the given propertyname
. If the property with the given name is not found, null is returned.- Parameters:
name
- the name of the property.- Returns:
- the json string object.
- Throws:
JsonParsingException
- if the json object identified by the given property is not a string.
-
getAsInstant
Returns anInstant
identified by the given propertyname
. If the property with the given name is not found, null is returned.- Parameters:
name
- the name of the property.- Returns:
- the
Instant
object. - Throws:
JsonParsingException
- if the json object identified by the given property does not represent a date in unix time.
-
getAsLong
Returns aLong
identified by the given propertyname
. If the property with the given name is not found, null is returned.- Parameters:
name
- the name of property.- Returns:
- the
Long
object. - Throws:
JsonParsingException
- if the json object identified by the given property does not represent a long value
-
getJsonObject
Returns a nested JSON object as @{link JsonObject} instance.- Parameters:
name
- the name of property.- Returns:
- the
JsonObject
. - Throws:
JsonParsingException
- if the json object identified by the given property is not a JSON object structure.
-
getJsonObjects
Returns a nested array of JSON objects as list ofJsonObject
instances. If the property with the given name is not found, an empty list is returned.- Parameters:
name
- the name of property.- Returns:
- a list of
JsonObject
instances. - Throws:
JsonParsingException
- if the json object identified by the given property is not an array of JSON objects.
-
getKeyValueMap
Returns a key-value map of the JSON properties.Example:
{ @code String vcapServices = System.getenv(CFConstants.VCAP_SERVICES); JsonObject serviceJsonObject = new DefaultJsonObject(vcapServices).getJsonObjects(Service.XSUAA.getCFName()) .get(0); Map<String, String> xsuaaConfigMap = serviceJsonObject.getKeyValueMap(); Map<String, String> credentialsMap = serviceJsonObject.getJsonObject(CFConstants.CREDENTIALS) .getKeyValueMap(); }
- Returns:
- the json properties as key-value map
-
asJsonString
String asJsonString()Returns the json object as a json string.- Returns:
- the json object in string representation.
-