Package io.openems.common.utils
Class JsonUtils.JsonObjectBuilder
- java.lang.Object
-
- io.openems.common.utils.JsonUtils.JsonObjectBuilder
-
- Enclosing class:
- JsonUtils
public static class JsonUtils.JsonObjectBuilder extends java.lang.Object
A temporary builder class for JsonObjects.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
JsonObjectBuilder()
protected
JsonObjectBuilder(com.google.gson.JsonObject j)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JsonUtils.JsonObjectBuilder
add(java.lang.String property, com.google.gson.JsonElement value)
Add aJsonElement
value to theJsonObject
.JsonUtils.JsonObjectBuilder
addProperty(java.lang.String property, boolean value)
Add a boolean value to theJsonObject
.JsonUtils.JsonObjectBuilder
addProperty(java.lang.String property, double value)
Add a double value to theJsonObject
.JsonUtils.JsonObjectBuilder
addProperty(java.lang.String property, int value)
Add a int value to theJsonObject
.JsonUtils.JsonObjectBuilder
addProperty(java.lang.String property, long value)
Add a long value to theJsonObject
.JsonUtils.JsonObjectBuilder
addProperty(java.lang.String property, java.lang.Enum<?> value)
Add aEnum
value to theJsonObject
.JsonUtils.JsonObjectBuilder
addProperty(java.lang.String property, java.lang.String value)
Add a String value to theJsonObject
.JsonUtils.JsonObjectBuilder
addProperty(java.lang.String property, java.time.ZonedDateTime value)
Add aZonedDateTime
value to theJsonObject
.JsonUtils.JsonObjectBuilder
addPropertyIfNotNull(java.lang.String property, java.lang.Boolean value)
Add aBoolean
value to theJsonObject
.JsonUtils.JsonObjectBuilder
addPropertyIfNotNull(java.lang.String property, java.lang.Double value)
Add aDouble
value to theJsonObject
if it is not null.JsonUtils.JsonObjectBuilder
addPropertyIfNotNull(java.lang.String property, java.lang.Enum<?> value)
Add aEnum
value to theJsonObject
if it is not null.JsonUtils.JsonObjectBuilder
addPropertyIfNotNull(java.lang.String property, java.lang.Integer value)
Add anInteger
value to theJsonObject
if it is not null.JsonUtils.JsonObjectBuilder
addPropertyIfNotNull(java.lang.String property, java.lang.Long value)
Add aLong
value to theJsonObject
if it is not null.JsonUtils.JsonObjectBuilder
addPropertyIfNotNull(java.lang.String property, java.lang.String value)
Add aString
value to theJsonObject
if it is not null.JsonUtils.JsonObjectBuilder
addPropertyIfNotNull(java.lang.String property, java.time.ZonedDateTime value)
Add aZonedDateTime
value to theJsonObject
if it is not null.com.google.gson.JsonObject
build()
Return the builtJsonObject
.JsonUtils.JsonObjectBuilder
onlyIf(boolean expression, java.util.function.Consumer<JsonUtils.JsonObjectBuilder> ifTrueCallback)
Call a method on a JsonObjectBuilder if an expression is true.
-
-
-
Method Detail
-
add
public JsonUtils.JsonObjectBuilder add(java.lang.String property, com.google.gson.JsonElement value)
Add aJsonElement
value to theJsonObject
.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addProperty
public JsonUtils.JsonObjectBuilder addProperty(java.lang.String property, boolean value)
Add a boolean value to theJsonObject
.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addProperty
public JsonUtils.JsonObjectBuilder addProperty(java.lang.String property, double value)
Add a double value to theJsonObject
.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addProperty
public JsonUtils.JsonObjectBuilder addProperty(java.lang.String property, int value)
Add a int value to theJsonObject
.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addProperty
public JsonUtils.JsonObjectBuilder addProperty(java.lang.String property, long value)
Add a long value to theJsonObject
.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addProperty
public JsonUtils.JsonObjectBuilder addProperty(java.lang.String property, java.lang.String value)
Add a String value to theJsonObject
.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addProperty
public JsonUtils.JsonObjectBuilder addProperty(java.lang.String property, java.lang.Enum<?> value)
Add aEnum
value to theJsonObject
.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addProperty
public JsonUtils.JsonObjectBuilder addProperty(java.lang.String property, java.time.ZonedDateTime value)
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
public JsonUtils.JsonObjectBuilder addPropertyIfNotNull(java.lang.String property, java.lang.Boolean value)
Add aBoolean
value to theJsonObject
.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addPropertyIfNotNull
public JsonUtils.JsonObjectBuilder addPropertyIfNotNull(java.lang.String property, java.lang.Double value)
Add aDouble
value to theJsonObject
if it is not null.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addPropertyIfNotNull
public JsonUtils.JsonObjectBuilder addPropertyIfNotNull(java.lang.String property, java.lang.Integer value)
Add anInteger
value to theJsonObject
if it is not null.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addPropertyIfNotNull
public JsonUtils.JsonObjectBuilder addPropertyIfNotNull(java.lang.String property, java.lang.Long value)
Add aLong
value to theJsonObject
if it is not null.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addPropertyIfNotNull
public JsonUtils.JsonObjectBuilder addPropertyIfNotNull(java.lang.String property, java.lang.String value)
Add aString
value to theJsonObject
if it is not null.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addPropertyIfNotNull
public JsonUtils.JsonObjectBuilder addPropertyIfNotNull(java.lang.String property, java.lang.Enum<?> value)
Add aEnum
value to theJsonObject
if it is not null.- Parameters:
property
- the keyvalue
- the value- Returns:
- the
JsonUtils.JsonObjectBuilder
-
addPropertyIfNotNull
public JsonUtils.JsonObjectBuilder addPropertyIfNotNull(java.lang.String property, java.time.ZonedDateTime value)
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, java.util.function.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
-
-