public interface JsonObject
| Modifier and Type | Method and Description |
|---|---|
String |
asJsonString()
Returns the json object as a json string.
|
boolean |
contains(String name) |
java.time.Instant |
getAsInstant(String name)
Returns an
Instant identified by the given property name. |
<T> List<T> |
getAsList(String name,
Class<T> type)
Parses the json object for the given property
name and returns a list
of type T. |
Long |
getAsLong(String name)
Returns a
Long identified by the given property name. |
String |
getAsString(String name)
Returns the string identified by the given property
name. |
List<String> |
getAsStringList(String name)
Parses the json object for the given property
name and returns a
String list. |
JsonObject |
getJsonObject(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 of
JsonObject
instances. |
Map<String,String> |
getKeyValueMap()
Returns a key-value map of the JSON properties.
|
boolean |
isEmpty()
Method to check if the underlying json object is empty.
|
boolean contains(String name)
name - the name of the property.boolean isEmpty()
<T> List<T> getAsList(String name, Class<T> type)
name and returns a list
of type T. If the property with the given name is not found, an empty
list is returned.T - the type of the list elements.name - the property inside this json object which contains a list as
values of type T.type - type parameter for generic type T.T.JsonParsingException - if the json object with the given key is not a list or list
elements are not of type T.List<String> getAsStringList(String name)
name 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"]name - the property inside this json object which contains a String list.JsonParsingException - if the json object with the given key is not a String array or of
type String.getAsString(java.lang.String)@Nullable String getAsString(String name)
name. If the
property with the given name is not found, null is returned.name - the name of the property.JsonParsingException - if the json object identified by the given property is not a
string.@Nullable java.time.Instant getAsInstant(String name)
Instant identified by the given property name. If
the property with the given name is not found, null is returned.name - the name of the property.Instant object.JsonParsingException - if the json object identified by the given property does not
represent a date in unix time.@Nullable Long getAsLong(String name)
Long identified by the given property name. If the
property with the given name is not found, null is returned.name - Long object.JsonParsingException - if the json object identified by the given property does not
represent a long value@Nullable JsonObject getJsonObject(String name)
name - the name of property.JsonObject.JsonParsingException - if the json object identified by the given property is not a JSON
object structure.List<JsonObject> getJsonObjects(String name)
JsonObject
instances. If the property with the given name is not found, an empty list is
returned.name - the name of property.JsonObject instances.JsonParsingException - if the json object identified by the given property is not an
array of JSON objects.Map<String,String> getKeyValueMap()
{
@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();
}
String asJsonString()
Copyright © 2020. All rights reserved.