Class JsonObject.Builder
java.lang.Object
com.revetsec.json.JsonObject.Builder
- Enclosing class:
JsonObject
Builds a
JsonObject one member at a time, keeping the order in which members are added.
Each put adds exactly one member, and a name that is already present throws
IllegalArgumentException rather than replacing the earlier value. Every check runs in put, so
build() never fails. A builder may be reused: each build() returns a snapshot of the members
added so far.
- Since:
- 1.0.0
- Author:
- Mark Allen
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Returns an object holding the members added so far, in the order they were added.Adds a member.Adds a member whose value is a JSON boolean.Adds a member whose value is a JSON number.Adds a member whose value is a JSON string.put(@NonNull String name, @NonNull BigDecimal value) Adds a member whose value is a JSON number, held exactly (seeJsonNumber.fromValue(BigDecimal)).Adds a member whose value is the JSONnull.toString()
-
Method Details
-
put
@CanIgnoreReturnValue public @NonNull JsonObject.Builder put(@NonNull String name, @NonNull JsonValue value) Adds a member.- Parameters:
name- the member namevalue- the member value- Returns:
- this builder
- Throws:
NullPointerException- if an argument isnullIllegalArgumentException- ifnamecontains an unpaired surrogate or is already present, or the object would nest more than 64 deep- Since:
- 1.0.0
-
put
@CanIgnoreReturnValue public @NonNull JsonObject.Builder put(@NonNull String name, @NonNull String value) Adds a member whose value is a JSON string.- Parameters:
name- the member namevalue- the string- Returns:
- this builder
- Throws:
NullPointerException- if an argument isnullIllegalArgumentException- ifnameorvaluecontains an unpaired surrogate, ornameis already present- Since:
- 1.0.0
-
put
@CanIgnoreReturnValue public @NonNull JsonObject.Builder put(@NonNull String name, @NonNull Long value) Adds a member whose value is a JSON number.- Parameters:
name- the member namevalue- the number- Returns:
- this builder
- Throws:
NullPointerException- if an argument isnullIllegalArgumentException- ifnamecontains an unpaired surrogate or is already present- Since:
- 1.0.0
-
put
@CanIgnoreReturnValue public @NonNull JsonObject.Builder put(@NonNull String name, @NonNull BigDecimal value) Adds a member whose value is a JSON number, held exactly (seeJsonNumber.fromValue(BigDecimal)).- Parameters:
name- the member namevalue- the number- Returns:
- this builder
- Throws:
NullPointerException- if an argument isnullIllegalArgumentException- ifvalueis outside the caps ofJsonNumber, ornamecontains an unpaired surrogate or is already present- Since:
- 1.0.0
-
put
@CanIgnoreReturnValue public @NonNull JsonObject.Builder put(@NonNull String name, @NonNull Boolean value) Adds a member whose value is a JSON boolean.- Parameters:
name- the member namevalue- the boolean- Returns:
- this builder
- Throws:
NullPointerException- if an argument isnullIllegalArgumentException- ifnamecontains an unpaired surrogate or is already present- Since:
- 1.0.0
-
putNull
Adds a member whose value is the JSONnull.- Parameters:
name- the member name- Returns:
- this builder
- Throws:
NullPointerException- ifnameisnullIllegalArgumentException- ifnamecontains an unpaired surrogate or is already present- Since:
- 1.0.0
-
build
Returns an object holding the members added so far, in the order they were added.- Returns:
- the JSON object;
JsonObject.emptyInstance()if no member was added - Since:
- 1.0.0
-
toString
-