Class ApiJsonBuilder<T extends ApiJsonBuilder<T>>
- java.lang.Object
-
- io.helidon.integrations.common.rest.ApiJsonBuilder<T>
-
- Type Parameters:
T
- type of the subclass
- Direct Known Subclasses:
ApiJsonRequest
,CreateSecret.SecretContent
,DecryptBatch.BatchEntry
,EncryptBatch.BatchEntry
,PostMetricData.MetricData
,PostMetricData.MetricDataPoint
public abstract class ApiJsonBuilder<T extends ApiJsonBuilder<T>> extends Object
Common base class for builders that construct a JSON object.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ApiJsonBuilder()
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected T
add(String name, boolean value)
Add custom boolean to payload.protected T
add(String name, double value)
Add custom double to payload.protected T
add(String name, int value)
Add custom int to payload.protected T
add(String name, long value)
Add custom long to payload.protected T
add(String name, ApiJsonBuilder<?> object)
Add a custom object to payload.protected T
add(String name, String value)
Add custom string to payload.protected T
addBase64(String name, Base64Value base64Value)
Add a string encoded with base64.protected T
addToArray(String name, boolean element)
Add an element to an array.protected T
addToArray(String name, double element)
Add an element to an array.protected T
addToArray(String name, int element)
Add an element to an array.protected T
addToArray(String name, long element)
Add an element to an array.protected T
addToArray(String name, ApiJsonBuilder<?> element)
Add an object to an array.protected T
addToArray(String name, String element)
Add an element to an array.protected T
addToObject(String name, String key, boolean value)
Add a key/value pair to a named object.protected T
addToObject(String name, String key, double value)
Add a key/value pair to a named object.protected T
addToObject(String name, String key, int value)
Add a key/value pair to a named object.protected T
addToObject(String name, String key, long value)
Add a key/value pair to a named object.protected T
addToObject(String name, String key, String value)
Add a key/value pair to a named object.protected T
emptyArray(String name)
Configure an empty array.protected T
me()
Can be returned by subclasses that can be subclassed again.protected void
postBuild(JsonBuilderFactory factory, JsonObjectBuilder payload)
Called after adding properties defined in this request.protected void
preBuild(JsonBuilderFactory factory, JsonObjectBuilder payload)
Called before adding properties defined in this request.Optional<JsonObject>
toJson(JsonBuilderFactory factory)
Create a JSON object from this builder.
-
-
-
Method Detail
-
toJson
public Optional<JsonObject> toJson(JsonBuilderFactory factory)
Create a JSON object from this builder.- Parameters:
factory
- builder factory to create objects- Returns:
- JSON object or empty
-
me
protected T me()
Can be returned by subclasses that can be subclassed again.- Returns:
- this instance as a subclass type
-
preBuild
protected void preBuild(JsonBuilderFactory factory, JsonObjectBuilder payload)
Called before adding properties defined in this request.- Parameters:
factory
- json factorypayload
- payload builder
-
postBuild
protected void postBuild(JsonBuilderFactory factory, JsonObjectBuilder payload)
Called after adding properties defined in this request.- Parameters:
factory
- json factorypayload
- payload builder
-
addToArray
protected T addToArray(String name, String element)
Add an element to an array.- Parameters:
name
- key in the json payloadelement
- element of the array- Returns:
- updated request
-
addToArray
protected T addToArray(String name, int element)
Add an element to an array.- Parameters:
name
- key in the json payloadelement
- element of the array- Returns:
- updated request
-
addToArray
protected T addToArray(String name, long element)
Add an element to an array.- Parameters:
name
- key in the json payloadelement
- element of the array- Returns:
- updated request
-
addToArray
protected T addToArray(String name, double element)
Add an element to an array.- Parameters:
name
- key in the json payloadelement
- element of the array- Returns:
- updated request
-
addToArray
protected T addToArray(String name, boolean element)
Add an element to an array.- Parameters:
name
- key in the json payloadelement
- element of the array- Returns:
- updated request
-
add
protected T add(String name, String value)
Add custom string to payload. If such a name is already added, it will be replaced.- Parameters:
name
- json keyvalue
- json String value- Returns:
- updated request
-
add
protected T add(String name, int value)
Add custom int to payload. If such a name is already added, it will be replaced.- Parameters:
name
- json keyvalue
- json value- Returns:
- updated request
-
add
protected T add(String name, double value)
Add custom double to payload. If such a name is already added, it will be replaced.- Parameters:
name
- json keyvalue
- json value- Returns:
- updated request
-
add
protected T add(String name, long value)
Add custom long to payload. If such a name is already added, it will be replaced.- Parameters:
name
- json keyvalue
- json value- Returns:
- updated request
-
add
protected T add(String name, boolean value)
Add custom boolean to payload. If such a name is already added, it will be replaced.- Parameters:
name
- json keyvalue
- json value- Returns:
- updated request
-
add
protected T add(String name, ApiJsonBuilder<?> object)
Add a custom object to payload.- Parameters:
name
- json keyobject
- json value- Returns:
- updated request
-
addBase64
protected T addBase64(String name, Base64Value base64Value)
Add a string encoded with base64.- Parameters:
name
- json keybase64Value
- base64 data- Returns:
- updated request
-
emptyArray
protected T emptyArray(String name)
Configure an empty array.- Parameters:
name
- name of the property- Returns:
- updated builder
-
addToArray
protected T addToArray(String name, ApiJsonBuilder<?> element)
Add an object to an array.- Parameters:
name
- name of the nested propertyelement
- aApiJsonBuilder
of the element of the array- Returns:
- updated builder
-
addToObject
protected T addToObject(String name, String key, String value)
Add a key/value pair to a named object.- Parameters:
name
- name of the object to create under the rootkey
- key of the nested propertyvalue
- value of the nested property- Returns:
- updated builder
-
addToObject
protected T addToObject(String name, String key, int value)
Add a key/value pair to a named object.- Parameters:
name
- name of the object to create under the rootkey
- key of the nested propertyvalue
- value of the nested property- Returns:
- updated builder
-
addToObject
protected T addToObject(String name, String key, long value)
Add a key/value pair to a named object.- Parameters:
name
- name of the object to create under the rootkey
- key of the nested propertyvalue
- value of the nested property- Returns:
- updated builder
-
addToObject
protected T addToObject(String name, String key, double value)
Add a key/value pair to a named object.- Parameters:
name
- name of the object to create under the rootkey
- key of the nested propertyvalue
- value of the nested property- Returns:
- updated builder
-
-