public class JsonArrayBuilder extends Object
JsonArray
from scratch. It uses builder pattern
to build the array model and the builder methods can be chained while
building the JSON array.
For example, for the following JSON array
[
{ "type": "home", "number": "212 555-1234" },
{ "type": "fax", "number": "646 555-4567" }
]
a JsonArray instance can be built using:
JsonArray value = new JsonArrayBuilder()
.add(new JsonObjectBuilder()
.add("type", "home")
.add("number", "212 555-1234"))
.add(new JsonObjectBuilder()
.add("type", "fax")
.add("number", "646 555-4567"))
.build();
JsonObjectBuilder
Constructor and Description |
---|
JsonArrayBuilder()
Constructs a
JsonArrayBuilder that initializes an empty JSON
array that is being built. |
Modifier and Type | Method and Description |
---|---|
JsonArrayBuilder |
add(BigDecimal value)
Adds the specified value as a JSON number value to the array
that is being built.
|
JsonArrayBuilder |
add(BigInteger value)
Adds the specified value as a JSON number value to the array
that is being built.
|
JsonArrayBuilder |
add(boolean value)
Adds a JSON true or false value to the array that is being built.
|
JsonArrayBuilder |
add(double value)
Adds the specified value as a JSON number value to the array
that is being built.
|
JsonArrayBuilder |
add(int value)
Adds the specified value as a JSON number value to the array
that is being built.
|
JsonArrayBuilder |
add(JsonArrayBuilder builder)
Adds a JsonArray from the specified builder to the array that
is being built.
|
JsonArrayBuilder |
add(JsonObjectBuilder builder)
Adds a JsonObject from the specified builder to the array that
is being built.
|
JsonArrayBuilder |
add(JsonValue value)
Adds the specified value to the array that is being built.
|
JsonArrayBuilder |
add(long value)
Adds the specified value as a JSON number value to the array
that is being built.
|
JsonArrayBuilder |
add(String value)
Adds the specified value as a JSON string value to the array
that is being built.
|
JsonArrayBuilder |
addNull()
Adds a JSON null value to the array that is being built.
|
JsonArray |
build()
Returns the array that is being built
|
public JsonArrayBuilder()
JsonArrayBuilder
that initializes an empty JSON
array that is being built.public JsonArrayBuilder add(JsonValue value)
value
- a JSON valuepublic JsonArrayBuilder add(String value)
value
- stringpublic JsonArrayBuilder add(BigDecimal value)
value
- a numberJsonNumber
public JsonArrayBuilder add(BigInteger value)
value
- a numberJsonNumber
public JsonArrayBuilder add(int value)
value
- a numberJsonNumber
public JsonArrayBuilder add(long value)
value
- a numberJsonNumber
public JsonArrayBuilder add(double value)
value
- a numberNumberFormatException
- if value is Not-a-Number(NaN) or infinityJsonNumber
public JsonArrayBuilder add(boolean value)
value
- a booleanpublic JsonArrayBuilder addNull()
public JsonArrayBuilder add(JsonObjectBuilder builder)
public JsonArrayBuilder add(JsonArrayBuilder builder)
public JsonArray build()
Copyright © 2013. All Rights Reserved.