-
public interface JsonArrayBuilder
A builder for creatingJsonArray
models from scratch. This interface initializes an empty JSON array model and provides methods to add values to the array model and to return the resulting array. The methods in this class can be chained to add multiple values to the array.The class
Json
contains methods to create the builder object. The example code below shows how to build an emptyJsonArray
instance.JsonArray array = Json.createArrayBuilder().build();
The class
JsonBuilderFactory
also contains methods to createJsonArrayBuilder
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 aJsonArray
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:
JsonObjectBuilder
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method and Description JsonArrayBuilder
add(BigDecimal value)
Adds a value to the array as aJsonNumber
.JsonArrayBuilder
add(BigInteger value)
Adds a value to the array as aJsonNumber
.JsonArrayBuilder
add(boolean value)
Adds aJsonValue.TRUE
orJsonValue.FALSE
value to the array.JsonArrayBuilder
add(double value)
Adds a value to the array as aJsonNumber
.JsonArrayBuilder
add(int value)
Adds a value to the array as aJsonNumber
.JsonArrayBuilder
add(JsonArrayBuilder builder)
Adds aJsonArray
from an array builder to the array.JsonArrayBuilder
add(JsonObjectBuilder builder)
Adds aJsonObject
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 aJsonNumber
.JsonArrayBuilder
add(String value)
Adds a value to the array as aJsonString
.JsonArrayBuilder
addNull()
Adds aJsonValue.NULL
value to the array.JsonArray
build()
Returns the current array.
-
-
-
Method Detail
-
add
JsonArrayBuilder add(JsonValue value)
Adds a value to the array.- Parameters:
value
- the JSON value- Returns:
- this array builder
- Throws:
NullPointerException
- if the specified value is null
-
add
JsonArrayBuilder add(String value)
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
JsonArrayBuilder add(BigDecimal value)
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:
JsonNumber
-
add
JsonArrayBuilder add(BigInteger value)
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:
JsonNumber
-
add
JsonArrayBuilder add(int value)
Adds a value to the array as aJsonNumber
.- Parameters:
value
- the number value- Returns:
- this array builder
- See Also:
JsonNumber
-
add
JsonArrayBuilder add(long value)
Adds a value to the array as aJsonNumber
.- Parameters:
value
- the number value- Returns:
- this array builder
- See Also:
JsonNumber
-
add
JsonArrayBuilder add(double value)
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:
JsonNumber
-
add
JsonArrayBuilder add(boolean value)
Adds aJsonValue.TRUE
orJsonValue.FALSE
value to the array.- Parameters:
value
- the boolean value- Returns:
- this array builder
-
addNull
JsonArrayBuilder addNull()
Adds aJsonValue.NULL
value to the array.- Returns:
- this array builder
-
add
JsonArrayBuilder add(JsonObjectBuilder builder)
Adds aJsonObject
from an object builder to the array.- Parameters:
builder
- the object builder- Returns:
- this array builder
- Throws:
NullPointerException
- if the specified builder is null
-
add
JsonArrayBuilder add(JsonArrayBuilder builder)
Adds aJsonArray
from an array builder to the array.- Parameters:
builder
- the array builder- Returns:
- this array builder
- Throws:
NullPointerException
- if the specified builder is null
-
build
JsonArray build()
Returns the current array.- Returns:
- the current JSON array
-
-
Document created the 11/06/2005, last modified the 18/08/2025
Source of the printed document:https://www.gaudry.be/en/java-api-javaee-rf-javax/json/JsonArrayBuilder.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author of this site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.