Package io.openems.common.utils
Class JsonUtils.JsonObjectBuilder
java.lang.Object
io.openems.common.utils.JsonUtils.JsonObjectBuilder
- Enclosing class:
JsonUtils
A temporary builder class for JsonObjects.
-
Constructor Summary
ModifierConstructorDescriptionprotected
protected
JsonObjectBuilder
(com.google.gson.JsonObject j) -
Method Summary
Modifier and TypeMethodDescriptionAdd aJsonElement
value to theJsonObject
.addProperty
(String property, boolean value) Add a boolean value to theJsonObject
.addProperty
(String property, double value) Add a double value to theJsonObject
.addProperty
(String property, int value) Add a int value to theJsonObject
.addProperty
(String property, long value) Add a long value to theJsonObject
.addProperty
(String property, Enum<?> value) Add aEnum
value to theJsonObject
.addProperty
(String property, String value) Add a String value to theJsonObject
.addProperty
(String property, ZonedDateTime value) Add aZonedDateTime
value to theJsonObject
.addPropertyIfNotNull
(String property, Boolean value) Add aBoolean
value to theJsonObject
.addPropertyIfNotNull
(String property, Double value) Add aDouble
value to theJsonObject
if it is not null.addPropertyIfNotNull
(String property, Enum<?> value) Add aEnum
value to theJsonObject
if it is not null.addPropertyIfNotNull
(String property, Integer value) Add anInteger
value to theJsonObject
if it is not null.addPropertyIfNotNull
(String property, Long value) Add aLong
value to theJsonObject
if it is not null.addPropertyIfNotNull
(String property, String value) Add aString
value to theJsonObject
if it is not null.addPropertyIfNotNull
(String property, ZonedDateTime value) Add aZonedDateTime
value to theJsonObject
if it is not null.com.google.gson.JsonObject
build()
Return the builtJsonObject
.onlyIf
(boolean expression, Consumer<JsonUtils.JsonObjectBuilder> ifTrueCallback) Call a method on a JsonObjectBuilder if an expression is true.
-
Constructor Details
-
JsonObjectBuilder
protected JsonObjectBuilder() -
JsonObjectBuilder
protected JsonObjectBuilder(com.google.gson.JsonObject j)
-
-
Method Details
-
add
Add aJsonElement
value to theJsonObject
.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addProperty
Add a boolean value to theJsonObject
.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addProperty
Add a double value to theJsonObject
.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addProperty
Add a int value to theJsonObject
.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addProperty
Add a long value to theJsonObject
.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addProperty
Add a String value to theJsonObject
.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addProperty
Add aEnum
value to theJsonObject
.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addProperty
Add aZonedDateTime
value to theJsonObject
.The value gets added in the format of
DateTimeFormatter.ISO_INSTANT
.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addPropertyIfNotNull
Add aBoolean
value to theJsonObject
.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addPropertyIfNotNull
Add aDouble
value to theJsonObject
if it is not null.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addPropertyIfNotNull
Add anInteger
value to theJsonObject
if it is not null.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addPropertyIfNotNull
Add aLong
value to theJsonObject
if it is not null.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addPropertyIfNotNull
Add aString
value to theJsonObject
if it is not null.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addPropertyIfNotNull
Add aEnum
value to theJsonObject
if it is not null.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addPropertyIfNotNull
Add aZonedDateTime
value to theJsonObject
if it is not null.The value gets added in the format of
DateTimeFormatter.ISO_INSTANT
.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
onlyIf
public JsonUtils.JsonObjectBuilder onlyIf(boolean expression, Consumer<JsonUtils.JsonObjectBuilder> ifTrueCallback) Call a method on a JsonObjectBuilder if an expression is true.- Parameters:
expression
- the expressionifTrueCallback
- allows a lambda function onJsonUtils.JsonObjectBuilder
- Returns:
- the
JsonUtils.JsonObjectBuilder
-
build
public com.google.gson.JsonObject build()Return the builtJsonObject
.- Returns:
- the
JsonObject
-