Class ApiJsonParser
java.lang.Object
io.helidon.integrations.common.rest.ApiJsonParser
- Direct Known Subclasses:
ApiResponse
,CertificateGet.Response
,DbGet.Response
,Encrypt.Encrypted
,GetCubbyhole.Response
,GetKv1.Response
,GetKv2.Response
,Kv2Metadata
,ListSecrets.Response
Helper methods to process a returned JSON.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionisPresent
(JsonObject json, String name) If the property is present on the JSON object, returns a non-empty optional, otherwise returns an empty.protected static String
stringValue
(JsonValue value) Get a string value from a json value.toBoolean
(JsonObject json, String name) Get a boolean value.protected static Optional<byte[]>
toBytesBase64
(JsonObject json, String name) Get bytes from a base64 string value.toDouble
(JsonObject json, String name) Get a double value.toInstant
(JsonObject json, String name, DateTimeFormatter formatter) Get anInstant
value.toInt
(JsonObject json, String name) Get an int value.toList
(JsonObject json, String name) Convert a JSON array in the JSON object to a list of strings.toLong
(JsonObject json, String name) Get a long value.toMap
(JsonObject json, String name) Get a map value.protected static Optional<JsonObject>
toObject
(JsonObject json, String name) Get a child JSON object.toString
(JsonObject json, String name) Get a string value.
-
Constructor Details
-
ApiJsonParser
public ApiJsonParser()
-
-
Method Details
-
stringValue
Get a string value from a json value.- Parameters:
value
- Json value- Returns:
- string representation of the value.
- Throws:
ApiException
- in case the value is array or object
-
toList
Convert a JSON array in the JSON object to a list of strings.- Parameters:
json
- JSON objectname
- name of the array in the object- Returns:
- list from the array, or empty if the array does not exist or is null
-
toBytesBase64
Get bytes from a base64 string value.- Parameters:
json
- JSON objectname
- name of the property- Returns:
- bytes or empty if the property does not exist or is null
-
toObject
Get a child JSON object.- Parameters:
json
- JSON objectname
- name of the property- Returns:
- JSON object or empty if the property does not exist or is null
-
toString
Get a string value.- Parameters:
json
- JSON objectname
- name of the property- Returns:
- string or empty if the property does not exist or is null
-
toInt
Get an int value.- Parameters:
json
- JSON objectname
- name of the property- Returns:
- int or empty if the property does not exist or is null
-
toLong
Get a long value.- Parameters:
json
- JSON objectname
- name of the property- Returns:
- long or empty if the property does not exist or is null
-
toDouble
Get a double value.- Parameters:
json
- JSON objectname
- name of the property- Returns:
- double or empty if the property does not exist or is null
-
toBoolean
Get a boolean value.- Parameters:
json
- JSON objectname
- name of the property- Returns:
- boolean or empty if the property does not exist or is null
-
toInstant
protected static Optional<Instant> toInstant(JsonObject json, String name, DateTimeFormatter formatter) Get anInstant
value.- Parameters:
json
- JSON objectname
- name of the propertyformatter
- to use when parsing the string value- Returns:
- instant or empty if the property does not exist or is null
-
toMap
Get a map value.- Parameters:
json
- JSON objectname
- name of the property- Returns:
- map with property key/value pairs, or empty if the property does not exist or is null
-
isPresent
If the property is present on the JSON object, returns a non-empty optional, otherwise returns an empty.- Parameters:
json
- JSON objectname
- name of the property- Returns:
- non-empty optional if the property exists and is not null
-