Interface JsonArrayBuilder
JsonArray models from scratch, and for
modifying a existing JsonArray.
A JsonArrayBuilder can start with an empty or a non-empty
JSON array model. This interface provides methods to add, insert, remove
and replace values in the JSON array model.
Methods in this class can be chained to perform multiple values to the array.
The class Json contains methods to create the builder
object. The example code below shows how to build an empty JsonArray
instance.
JsonArray array = Json.createArrayBuilder().build();
The class JsonBuilderFactory also contains methods to create
JsonArrayBuilder instances. A factory instance can be used to create
multiple builder instances with the same configuration. This the preferred
way to create multiple instances.
The example code below shows how to build a JsonArray object
that represents the following JSON array:
[
{ "type": "home", "number": "212 555-1234" },
{ "type": "fax", "number": "646 555-4567" }
]
The following code creates the JSON array above:
JsonBuilderFactory factory = Json.createBuilderFactory(config);
JsonArray value = factory.createArrayBuilder()
.add(factory.createObjectBuilder()
.add("type", "home")
.add("number", "212 555-1234"))
.add(factory.createObjectBuilder()
.add("type", "fax")
.add("number", "646 555-4567"))
.build();
This class does not allow null to be used as a
value while building the JSON array
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionadd(boolean value) Adds aJsonValue.TRUEorJsonValue.FALSEvalue to the array.add(double value) Adds a value to the array as aJsonNumber.add(int value) Adds a value to the array as aJsonNumber.default JsonArrayBuilderadd(int index, boolean value) Adds aJsonValue.TRUEorJsonValue.FALSEvalue to the array at the specified position.default JsonArrayBuilderadd(int index, double value) Adds a value to the array as aJsonNumberat the specified position.default JsonArrayBuilderadd(int index, int value) Adds a value to the array as aJsonNumberat the specified position.default JsonArrayBuilderadd(int index, long value) Adds a value to the array as aJsonNumberat the specified position.default JsonArrayBuilderadd(int index, JsonArrayBuilder builder) Adds aJsonArrayfrom an array builder to the array at the specified position.default JsonArrayBuilderadd(int index, JsonObjectBuilder builder) Adds aJsonObjectfrom an object builder to the array at the specified position.default JsonArrayBuilderInserts a value to the array at the specified position.default JsonArrayBuilderAdds a value to the array as aJsonStringat the specified position.default JsonArrayBuilderadd(int index, BigDecimal value) Adds a value to the array as aJsonNumberat the specified position.default JsonArrayBuilderadd(int index, BigInteger value) Adds a value to the array as aJsonNumberat the specified position.add(long value) Adds a value to the array as aJsonNumber.add(JsonArrayBuilder builder) Adds aJsonArrayfrom an array builder to the array.add(JsonObjectBuilder builder) Adds aJsonObjectfrom an object builder to the array.Adds a value to the array.Adds a value to the array as aJsonString.add(BigDecimal value) Adds a value to the array as aJsonNumber.add(BigInteger value) Adds a value to the array as aJsonNumber.default JsonArrayBuilderaddAll(JsonArrayBuilder builder) Adds all elements of the array in the specified array builder to the array.addNull()Adds aJsonValue.NULLvalue to the array.default JsonArrayBuilderaddNull(int index) Adds aJsonValue.NULLvalue to the array at the specified position.build()Returns the current array.default JsonArrayBuilderremove(int index) Remove the value in the array at the specified position.default JsonArrayBuilderset(int index, boolean value) Replaces a value in the array with aJsonValue.TRUEorJsonValue.FALSEvalue at the specified position.default JsonArrayBuilderset(int index, double value) Replaces a value in the array with the specified value as aJsonNumberat the specified position.default JsonArrayBuilderset(int index, int value) Replaces a value in the array with the specified value as aJsonNumberat the specified position.default JsonArrayBuilderset(int index, long value) Replaces a value in the array with the specified value as aJsonNumberat the specified position.default JsonArrayBuilderset(int index, JsonArrayBuilder builder) Replaces a value in the array with the specified value as aJsonArrayfrom an array builder at the specified position.default JsonArrayBuilderset(int index, JsonObjectBuilder builder) Replaces a value in the array with the specified value as aJsonObjectfrom an object builder at the specified position.default JsonArrayBuilderReplaces a value in the array with the specified value at the specified position.default JsonArrayBuilderReplaces a value in the array with the specified value as aJsonStringat the specified position.default JsonArrayBuilderset(int index, BigDecimal value) Replaces a value in the array with the specified value as aJsonNumberat the specified position.default JsonArrayBuilderset(int index, BigInteger value) Replaces a value in the array with the specified value as aJsonNumberat the specified position.default JsonArrayBuildersetNull(int index) Replaces a value in the array with aJsonValue.NULLvalue at the specified position.
-
Method Details
-
add
Adds a value to the array.- Parameters:
value- the JSON value- Returns:
- this array builder
- Throws:
NullPointerException- if the specified value is null
-
add
Adds a value to the array as aJsonString.- Parameters:
value- the string value- Returns:
- this array builder
- Throws:
NullPointerException- if the specified value is null
-
add
Adds a value to the array as aJsonNumber.- Parameters:
value- the number value- Returns:
- this array builder
- Throws:
NullPointerException- if the specified value is null- See Also:
-
add
Adds a value to the array as aJsonNumber.- Parameters:
value- the number value- Returns:
- this array builder
- Throws:
NullPointerException- if the specified value is null- See Also:
-
add
Adds a value to the array as aJsonNumber.- Parameters:
value- the number value- Returns:
- this array builder
- See Also:
-
add
Adds a value to the array as aJsonNumber.- Parameters:
value- the number value- Returns:
- this array builder
- See Also:
-
add
Adds a value to the array as aJsonNumber.- Parameters:
value- the number value- Returns:
- this array builder
- Throws:
NumberFormatException- if the value is Not-a-Number (NaN) or infinity- See Also:
-
add
Adds aJsonValue.TRUEorJsonValue.FALSEvalue to the array.- Parameters:
value- the boolean value- Returns:
- this array builder
-
addNull
JsonArrayBuilder addNull()Adds aJsonValue.NULLvalue to the array.- Returns:
- this array builder
-
add
Adds aJsonObjectfrom an object builder to the array.- Parameters:
builder- the object builder- Returns:
- this array builder
- Throws:
NullPointerException- if the specified builder is null
-
add
Adds aJsonArrayfrom an array builder to the array.- Parameters:
builder- the array builder- Returns:
- this array builder
- Throws:
NullPointerException- if the specified builder is null
-
addAll
Adds all elements of the array in the specified array builder to the array.- Parameters:
builder- the array builder- Returns:
- this array builder
- Throws:
NullPointerException- if the specified builder is null- Since:
- 1.1
-
add
Inserts a value to the array at the specified position. Shifts the value currently at that position (if any) and any subsequent values to the right (adds one to their indices). Index starts with 0.- Parameters:
index- the position in the arrayvalue- the JSON value- Returns:
- this array builder
- Throws:
NullPointerException- if the specified value is nullIndexOutOfBoundsException- if the index is out of range(index < 0 || index > array size)- Since:
- 1.1
-
add
Adds a value to the array as aJsonStringat the specified position. Shifts the value currently at that position (if any) and any subsequent values to the right (adds one to their indices). Index starts with 0.- Parameters:
index- the position in the arrayvalue- the string value- Returns:
- this array builder
- Throws:
NullPointerException- if the specified value is nullIndexOutOfBoundsException- if the index is out of range(index < 0 || index > array size)- Since:
- 1.1
-
add
Adds a value to the array as aJsonNumberat the specified position. Shifts the value currently at that position (if any) and any subsequent values to the right (adds one to their indices). Index starts with 0.- Parameters:
index- the position in the arrayvalue- the number value- Returns:
- this array builder
- Throws:
NullPointerException- if the specified value is nullIndexOutOfBoundsException- if the index is out of range(index < 0 || index > array size)- Since:
- 1.1
- See Also:
-
add
Adds a value to the array as aJsonNumberat the specified position. Shifts the value currently at that position (if any) and any subsequent values to the right (adds one to their indices). Index starts with 0.- Parameters:
index- the position in the arrayvalue- the number value- Returns:
- this array builder
- Throws:
NullPointerException- if the specified value is nullIndexOutOfBoundsException- if the index is out of range(index < 0 || index > array size)- Since:
- 1.1
- See Also:
-
add
Adds a value to the array as aJsonNumberat the specified position. Shifts the value currently at that position (if any) and any subsequent values to the right (adds one to their indices). Index starts with 0.- Parameters:
index- the position in the arrayvalue- the number value- Returns:
- this array builder
- Throws:
IndexOutOfBoundsException- if the index is out of range(index < 0 || index > array size)- Since:
- 1.1
- See Also:
-
add
Adds a value to the array as aJsonNumberat the specified position. Shifts the value currently at that position (if any) and any subsequent values to the right (adds one to their indices). Index starts with 0.- Parameters:
index- the position in the arrayvalue- the number value- Returns:
- this array builder
- Throws:
IndexOutOfBoundsException- if the index is out of range(index < 0 || index > array size)- Since:
- 1.1
- See Also:
-
add
Adds a value to the array as aJsonNumberat the specified position. Shifts the value currently at that position (if any) and any subsequent values to the right (adds one to their indices). Index starts with 0.- Parameters:
index- the position in the arrayvalue- the number value- Returns:
- this array builder
- Throws:
NumberFormatException- if the value is Not-a-Number (NaN) or infinityIndexOutOfBoundsException- if the index is out of range(index < 0 || index > array size)- Since:
- 1.1
- See Also:
-
add
Adds aJsonValue.TRUEorJsonValue.FALSEvalue to the array at the specified position. Shifts the value currently at that position (if any) and any subsequent values to the right (adds one to their indices). Index starts with 0.- Parameters:
index- the position in the arrayvalue- the boolean value- Returns:
- this array builder
- Throws:
IndexOutOfBoundsException- if the index is out of range(index < 0 || index > array size)- Since:
- 1.1
-
addNull
Adds aJsonValue.NULLvalue to the array at the specified position. Shifts the value currently at that position (if any) and any subsequent values to the right (adds one to their indices). Index starts with 0.- Parameters:
index- the position in the array- Returns:
- this array builder
- Throws:
IndexOutOfBoundsException- if the index is out of range(index < 0 || index > array size)- Since:
- 1.1
-
add
Adds aJsonObjectfrom an object builder to the array at the specified position. Shifts the value currently at that position (if any) and any subsequent values to the right (adds one to their indices). Index starts with 0.- Parameters:
index- the position in the arraybuilder- the object builder- Returns:
- this array builder
- Throws:
NullPointerException- if the specified builder is nullIndexOutOfBoundsException- if the index is out of range(index < 0 || index > array size)- Since:
- 1.1
-
add
Adds aJsonArrayfrom an array builder to the array at the specified position. Shifts the value currently at that position (if any) and any subsequent values to the right (adds one to their indices). Index starts with 0.- Parameters:
index- the position in the arraybuilder- the array builder- Returns:
- this array builder
- Throws:
NullPointerException- if the specified builder is nullIndexOutOfBoundsException- if the index is out of range(index < 0 || index > array size)- Since:
- 1.1
-
set
Replaces a value in the array with the specified value at the specified position.- Parameters:
index- the position in the arrayvalue- the JSON value- Returns:
- this array builder
- Throws:
NullPointerException- if the specified value is nullIndexOutOfBoundsException- if the index is out of range(index < 0 || index >= array size)- Since:
- 1.1
-
set
Replaces a value in the array with the specified value as aJsonStringat the specified position.- Parameters:
index- the position in the arrayvalue- the string value- Returns:
- this array builder
- Throws:
NullPointerException- if the specified value is nullIndexOutOfBoundsException- if the index is out of range(index < 0 || index >= array size)- Since:
- 1.1
-
set
Replaces a value in the array with the specified value as aJsonNumberat the specified position.- Parameters:
index- the position in the arrayvalue- the number value- Returns:
- this array builder
- Throws:
NullPointerException- if the specified value is nullIndexOutOfBoundsException- if the index is out of range(index < 0 || index >= array size)- Since:
- 1.1
- See Also:
-
set
Replaces a value in the array with the specified value as aJsonNumberat the specified position.- Parameters:
index- the position in the arrayvalue- the number value- Returns:
- this array builder
- Throws:
NullPointerException- if the specified value is nullIndexOutOfBoundsException- if the index is out of range(index < 0 || index >= array size)- Since:
- 1.1
- See Also:
-
set
Replaces a value in the array with the specified value as aJsonNumberat the specified position.- Parameters:
index- the position in the arrayvalue- the number value- Returns:
- this array builder
- Throws:
IndexOutOfBoundsException- if the index is out of range(index < 0 || index >= array size)- Since:
- 1.1
- See Also:
-
set
Replaces a value in the array with the specified value as aJsonNumberat the specified position.- Parameters:
index- the position in the arrayvalue- the number value- Returns:
- this array builder
- Throws:
IndexOutOfBoundsException- if the index is out of range(index < 0 || index >= array size)- Since:
- 1.1
- See Also:
-
set
Replaces a value in the array with the specified value as aJsonNumberat the specified position.- Parameters:
index- the position in the arrayvalue- the number value- Returns:
- this array builder
- Throws:
NumberFormatException- if the value is Not-a-Number (NaN) or infinityIndexOutOfBoundsException- if the index is out of range(index < 0 || index >= array size)- Since:
- 1.1
- See Also:
-
set
Replaces a value in the array with aJsonValue.TRUEorJsonValue.FALSEvalue at the specified position.- Parameters:
index- the position in the arrayvalue- the boolean value- Returns:
- this array builder
- Throws:
IndexOutOfBoundsException- if the index is out of range(index < 0 || index >= array size)- Since:
- 1.1
-
setNull
Replaces a value in the array with aJsonValue.NULLvalue at the specified position.- Parameters:
index- the position in the array- Returns:
- this array builder
- Throws:
IndexOutOfBoundsException- if the index is out of range(index < 0 || index >= array size)- Since:
- 1.1
-
set
Replaces a value in the array with the specified value as aJsonObjectfrom an object builder at the specified position.- Parameters:
index- the position in the arraybuilder- the object builder- Returns:
- this array builder
- Throws:
NullPointerException- if the specified builder is nullIndexOutOfBoundsException- if the index is out of range(index < 0 || index >= array size)- Since:
- 1.1
-
set
Replaces a value in the array with the specified value as aJsonArrayfrom an array builder at the specified position.- Parameters:
index- the position in the arraybuilder- the array builder- Returns:
- this array builder
- Throws:
NullPointerException- if the specified builder is nullIndexOutOfBoundsException- if the index is out of range(index < 0 || index >= array size)- Since:
- 1.1
-
remove
Remove the value in the array at the specified position. Shift any subsequent values to the left (subtracts one from their indices.- Parameters:
index- the position in the array- Returns:
- this array builder
- Throws:
IndexOutOfBoundsException- if the index is out of range(index < 0 || index >= array size)- Since:
- 1.1
-
build
JsonArray build()Returns the current array.- Returns:
- the current JSON array
-