Package com.sap.cloud.security.json
Interface JsonObject
-
- All Superinterfaces:
Serializable
public interface JsonObject extends Serializable
Interface used to expose JSON data.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description StringasJsonString()Returns the json object as a json string.booleancontains(String name)InstantgetAsInstant(String name)Returns anInstantidentified by the given propertyname.<T> List<T>getAsList(String name, Class<T> type)Parses the json object for the given propertynameand returns a list of typeJsonObject.LonggetAsLong(String name)Returns aLongidentified by the given propertyname.StringgetAsString(String name)Returns the string identified by the given propertyname.List<String>getAsStringList(String name)Parses the json object for the given propertynameand returns a String list.JsonObjectgetJsonObject(String name)Returns a nested JSON object as @{link JsonObject} instance.List<JsonObject>getJsonObjects(String name)Returns a nested array of JSON objects as list ofJsonObjectinstances.Map<String,String>getKeyValueMap()Returns a key-value map of the JSON properties.booleanisEmpty()Method to check if the underlying json object is empty.
-
-
-
Method Detail
-
contains
boolean contains(String name)
- 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
<T> List<T> getAsList(String name, Class<T> type)
Parses the json object for the given propertynameand 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
List<String> getAsStringList(String name)
Parses the json object for the given propertynameand 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(java.lang.String)
-
getAsString
@Nullable String getAsString(String name)
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
@Nullable Instant getAsInstant(String name)
Returns anInstantidentified 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
Instantobject. - Throws:
JsonParsingException- if the json object identified by the given property does not represent a date in unix time.
-
getAsLong
@Nullable Long getAsLong(String name)
Returns aLongidentified 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
Longobject. - Throws:
JsonParsingException- if the json object identified by the given property does not represent a long value
-
getJsonObject
@Nullable JsonObject getJsonObject(String name)
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
List<JsonObject> getJsonObjects(String name)
Returns a nested array of JSON objects as list ofJsonObjectinstances. 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
JsonObjectinstances. - Throws:
JsonParsingException- if the json object identified by the given property is not an array of JSON objects.
-
getKeyValueMap
Map<String,String> 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.
-
-