public 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
JsonObjectBuilder
Modifier and Type | Method and Description |
---|---|
JsonArrayBuilder |
add(BigDecimal value)
Adds a value to the array as a
JsonNumber . |
JsonArrayBuilder |
add(BigInteger value)
Adds a value to the array as a
JsonNumber . |
JsonArrayBuilder |
add(boolean value)
Adds a
JsonValue.TRUE or JsonValue.FALSE value to the
array. |
JsonArrayBuilder |
add(double value)
Adds a value to the array as a
JsonNumber . |
JsonArrayBuilder |
add(int value)
Adds a value to the array as a
JsonNumber . |
default JsonArrayBuilder |
add(int index,
BigDecimal value)
Adds a value to the array as a
JsonNumber at the specified position. |
default JsonArrayBuilder |
add(int index,
BigInteger value)
Adds a value to the array as a
JsonNumber at the specified position. |
default JsonArrayBuilder |
add(int index,
boolean value)
Adds a
JsonValue.TRUE or JsonValue.FALSE value to the
array at the specified position. |
default JsonArrayBuilder |
add(int index,
double value)
Adds a value to the array as a
JsonNumber at the specified position. |
default JsonArrayBuilder |
add(int index,
int value)
Adds a value to the array as a
JsonNumber at the specified position. |
default JsonArrayBuilder |
add(int index,
JsonArrayBuilder builder)
Adds a
JsonArray from an array builder to the array at the specified position. |
default JsonArrayBuilder |
add(int index,
JsonObjectBuilder builder)
Adds a
JsonObject from an object builder to the array at the specified position. |
default JsonArrayBuilder |
add(int index,
JsonValue value)
Inserts a value to the array at the specified position.
|
default JsonArrayBuilder |
add(int index,
long value)
Adds a value to the array as a
JsonNumber at the specified position. |
default JsonArrayBuilder |
add(int index,
String value)
Adds a value to the array as a
JsonString at the specified position. |
JsonArrayBuilder |
add(JsonArrayBuilder builder)
Adds a
JsonArray from an array builder to the array. |
JsonArrayBuilder |
add(JsonObjectBuilder builder)
Adds a
JsonObject from an object builder to the array. |
JsonArrayBuilder |
add(JsonValue value)
Adds a value to the array.
|
JsonArrayBuilder |
add(long value)
Adds a value to the array as a
JsonNumber . |
JsonArrayBuilder |
add(String value)
Adds a value to the array as a
JsonString . |
default JsonArrayBuilder |
addAll(JsonArrayBuilder builder)
Adds all elements of the array in the specified array builder to the array.
|
JsonArrayBuilder |
addNull()
Adds a
JsonValue.NULL value to the array. |
default JsonArrayBuilder |
addNull(int index)
Adds a
JsonValue.NULL value to the array at the specified position. |
JsonArray |
build()
Returns the current array.
|
default JsonArrayBuilder |
remove(int index)
Remove the value in the array at the specified position.
|
default JsonArrayBuilder |
set(int index,
BigDecimal value)
Replaces a value in the array with the specified value as a
JsonNumber at the specified position. |
default JsonArrayBuilder |
set(int index,
BigInteger value)
Replaces a value in the array with the specified value as a
JsonNumber at the specified position. |
default JsonArrayBuilder |
set(int index,
boolean value)
Replaces a value in the array with
a
JsonValue.TRUE or JsonValue.FALSE value
at the specified position. |
default JsonArrayBuilder |
set(int index,
double value)
Replaces a value in the array with the specified value as a
JsonNumber at the specified position. |
default JsonArrayBuilder |
set(int index,
int value)
Replaces a value in the array with the specified value as a
JsonNumber at the specified position. |
default JsonArrayBuilder |
set(int index,
JsonArrayBuilder builder)
Replaces a value in the array with the specified value as a
JsonArray from an array builder at the specified position. |
default JsonArrayBuilder |
set(int index,
JsonObjectBuilder builder)
Replaces a value in the array with the specified value as a
JsonObject from an object builder at the specified position. |
default JsonArrayBuilder |
set(int index,
JsonValue value)
Replaces a value in the array with the specified value at the
specified position.
|
default JsonArrayBuilder |
set(int index,
long value)
Replaces a value in the array with the specified value as a
JsonNumber at the specified position. |
default JsonArrayBuilder |
set(int index,
String value)
Replaces a value in the array with the specified value as a
JsonString at the specified position. |
default JsonArrayBuilder |
setNull(int index)
Replaces a value in the array with
a
JsonValue.NULL value at the specified position. |
JsonArrayBuilder add(JsonValue value)
value
- the JSON valueNullPointerException
- if the specified value is nullJsonArrayBuilder add(String value)
JsonString
.value
- the string valueNullPointerException
- if the specified value is nullJsonArrayBuilder add(BigDecimal value)
JsonNumber
.value
- the number valueNullPointerException
- if the specified value is nullJsonNumber
JsonArrayBuilder add(BigInteger value)
JsonNumber
.value
- the number valueNullPointerException
- if the specified value is nullJsonNumber
JsonArrayBuilder add(int value)
JsonNumber
.value
- the number valueJsonNumber
JsonArrayBuilder add(long value)
JsonNumber
.value
- the number valueJsonNumber
JsonArrayBuilder add(double value)
JsonNumber
.value
- the number valueNumberFormatException
- if the value is Not-a-Number (NaN) or
infinityJsonNumber
JsonArrayBuilder add(boolean value)
JsonValue.TRUE
or JsonValue.FALSE
value to the
array.value
- the boolean valueJsonArrayBuilder addNull()
JsonValue.NULL
value to the array.JsonArrayBuilder add(JsonObjectBuilder builder)
JsonObject
from an object builder to the array.builder
- the object builderNullPointerException
- if the specified builder is nullJsonArrayBuilder add(JsonArrayBuilder builder)
JsonArray
from an array builder to the array.builder
- the array builderNullPointerException
- if the specified builder is nulldefault JsonArrayBuilder addAll(JsonArrayBuilder builder)
builder
- the array builderNullPointerException
- if the specified builder is nulldefault JsonArrayBuilder add(int index, JsonValue value)
index
- the position in the arrayvalue
- the JSON valueNullPointerException
- if the specified value is nullIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > array size)
default JsonArrayBuilder add(int index, String value)
JsonString
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.index
- the position in the arrayvalue
- the string valueNullPointerException
- if the specified value is nullIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > array size)
default JsonArrayBuilder add(int index, BigDecimal value)
JsonNumber
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.index
- the position in the arrayvalue
- the number valueNullPointerException
- if the specified value is nullIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > array size)
JsonNumber
default JsonArrayBuilder add(int index, BigInteger value)
JsonNumber
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.index
- the position in the arrayvalue
- the number valueNullPointerException
- if the specified value is nullIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > array size)
JsonNumber
default JsonArrayBuilder add(int index, int value)
JsonNumber
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.index
- the position in the arrayvalue
- the number valueIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > array size)
JsonNumber
default JsonArrayBuilder add(int index, long value)
JsonNumber
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.index
- the position in the arrayvalue
- the number valueIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > array size)
JsonNumber
default JsonArrayBuilder add(int index, double value)
JsonNumber
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.index
- the position in the arrayvalue
- the number valueNumberFormatException
- if the value is Not-a-Number (NaN) or
infinityIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > array size)
JsonNumber
default JsonArrayBuilder add(int index, boolean value)
JsonValue.TRUE
or JsonValue.FALSE
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.index
- the position in the arrayvalue
- the boolean valueIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > array size)
default JsonArrayBuilder addNull(int index)
JsonValue.NULL
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.index
- the position in the arrayIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > array size)
default JsonArrayBuilder add(int index, JsonObjectBuilder builder)
JsonObject
from 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.index
- the position in the arraybuilder
- the object builderNullPointerException
- if the specified builder is nullIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > array size)
default JsonArrayBuilder add(int index, JsonArrayBuilder builder)
JsonArray
from 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.index
- the position in the arraybuilder
- the array builderNullPointerException
- if the specified builder is nullIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > array size)
default JsonArrayBuilder set(int index, JsonValue value)
index
- the position in the arrayvalue
- the JSON valueNullPointerException
- if the specified value is nullIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= array size)
default JsonArrayBuilder set(int index, String value)
JsonString
at the specified position.index
- the position in the arrayvalue
- the string valueNullPointerException
- if the specified value is nullIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= array size)
default JsonArrayBuilder set(int index, BigDecimal value)
JsonNumber
at the specified position.index
- the position in the arrayvalue
- the number valueNullPointerException
- if the specified value is nullIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= array size)
JsonNumber
default JsonArrayBuilder set(int index, BigInteger value)
JsonNumber
at the specified position.index
- the position in the arrayvalue
- the number valueNullPointerException
- if the specified value is nullIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= array size)
JsonNumber
default JsonArrayBuilder set(int index, int value)
JsonNumber
at the specified position.index
- the position in the arrayvalue
- the number valueIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= array size)
JsonNumber
default JsonArrayBuilder set(int index, long value)
JsonNumber
at the specified position.index
- the position in the arrayvalue
- the number valueIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= array size)
JsonNumber
default JsonArrayBuilder set(int index, double value)
JsonNumber
at the specified position.index
- the position in the arrayvalue
- the number valueNumberFormatException
- if the value is Not-a-Number (NaN) or
infinityIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= array size)
JsonNumber
default JsonArrayBuilder set(int index, boolean value)
JsonValue.TRUE
or JsonValue.FALSE
value
at the specified position.index
- the position in the arrayvalue
- the boolean valueIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= array size)
default JsonArrayBuilder setNull(int index)
JsonValue.NULL
value at the specified position.index
- the position in the arrayIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= array size)
default JsonArrayBuilder set(int index, JsonObjectBuilder builder)
JsonObject
from an object builder at the specified position.index
- the position in the arraybuilder
- the object builderNullPointerException
- if the specified builder is nullIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= array size)
default JsonArrayBuilder set(int index, JsonArrayBuilder builder)
JsonArray
from an array builder at the specified position.index
- the position in the arraybuilder
- the array builderNullPointerException
- if the specified builder is nullIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= array size)
default JsonArrayBuilder remove(int index)
index
- the position in the arrayIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= array size)
JsonArray build()
Copyright © 2019 JBoss by Red Hat. All rights reserved.