Interface JsonObject
- All Superinterfaces:
Serializable
Interface used to expose JSON data.
-
Method Summary
Modifier and TypeMethodDescriptionReturns the json object as a json string.booleangetAsInstant(String name) Returns anInstantidentified by the given propertyname.<T> List<T> Parses the json object for the given propertynameand returns a list of typeT.Returns aLongidentified 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 propertynameand 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 ofJsonObjectinstances.Returns a key-value map of the JSON properties.booleanisEmpty()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 propertynameand returns a list of typeT. 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 typeT.type- type parameter for generic typeT.- Returns:
- the list of type
T. - Throws:
JsonParsingException- if the json object with the given key is not a list or list elements are not of typeT.
-
getAsStringList
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
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 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
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
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 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
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.
-