public class JsonArray extends Object implements Iterable<Object>, io.vertx.core.shareddata.impl.ClusterSerializable, Shareable
Constructor and Description |
---|
JsonArray()
Create an empty instance
|
JsonArray(Buffer buf)
Create an instance from a Buffer of JSON.
|
JsonArray(List list)
Create an instance from a List.
|
JsonArray(String json)
Create an instance from a String of JSON, this string must be a valid array otherwise an exception will be thrown.
|
Modifier and Type | Method and Description |
---|---|
JsonArray |
add(int pos,
Object value)
Add an Object to the JSON array at given position
pos . |
JsonArray |
add(Object value)
Add an Object to the JSON array.
|
JsonArray |
addAll(JsonArray array)
Appends all of the elements in the specified array to the end of this JSON array.
|
JsonArray |
addNull()
Add a null value to the JSON array.
|
JsonArray |
clear()
Remove all entries from the JSON array
|
boolean |
contains(Object value)
Does the JSON array contain the specified value? This method will scan the entire array until it finds a value
or reaches the end.
|
JsonArray |
copy()
Deep copy of the JSON array.
|
JsonArray |
copy(java.util.function.Function<Object,?> cloner)
Deep copy of the JSON array.
|
String |
encode()
Encode the JSON array to a string
|
String |
encodePrettily()
Encode the JSON array prettily as a string
|
boolean |
equals(Object o) |
byte[] |
getBinary(int pos)
Get the byte[] at position
pos in the array. |
Boolean |
getBoolean(int pos)
Get the Boolean at position
pos in the array, |
Buffer |
getBuffer(int pos)
Get the Buffer at position
pos in the array. |
Double |
getDouble(int pos)
Get the Double at position
pos in the array, |
Float |
getFloat(int pos)
Get the Float at position
pos in the array, |
java.time.Instant |
getInstant(int pos)
Get the Instant at position
pos in the array. |
Integer |
getInteger(int pos)
Get the Integer at position
pos in the array, |
JsonArray |
getJsonArray(int pos)
Get the JsonArray at position
pos in the array. |
JsonObject |
getJsonObject(int pos)
Get the JsonObject at position
pos in the array. |
List |
getList()
Get the underlying
List as is. |
Long |
getLong(int pos)
Get the Long at position
pos in the array, |
Number |
getNumber(int pos)
Get the Number at position
pos in the array, |
String |
getString(int pos)
Get the String at position
pos in the array, |
Object |
getValue(int pos)
Get the value with the specified key, as an Object with types respecting the limitations of JSON.
|
int |
hashCode() |
boolean |
hasNull(int pos)
Is there a null value at position pos?
|
boolean |
isEmpty()
Are there zero items in this JSON array?
|
Iterator<Object> |
iterator()
Get an Iterator over the values in the JSON array
|
int |
readFromBuffer(int pos,
Buffer buffer) |
Object |
remove(int pos)
Remove the value at the specified position in the JSON array.
|
boolean |
remove(Object value)
Remove the specified value from the JSON array.
|
JsonArray |
set(int pos,
Object value)
Set an Object to the JSON array at position
pos . |
JsonArray |
setNull(int pos)
Set a null value to the JSON array at position
pos . |
int |
size()
Get the number of values in this JSON array
|
java.util.stream.Stream<Object> |
stream()
Get a Stream over the entries in the JSON array.
|
Buffer |
toBuffer()
Encode this JSON object as buffer.
|
String |
toString() |
void |
writeToBuffer(Buffer buffer) |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
public JsonArray(String json)
Json.decodeValue(String)
and check the result is
a JSON array.json
- the string of JSONpublic JsonArray()
public JsonArray(List list)
list
- the underlying backing listpublic JsonArray(Buffer buf)
buf
- the buffer of JSON.public String getString(int pos)
pos
in the array,pos
- the position in the arraypublic Number getNumber(int pos)
pos
in the array,pos
- the position in the arrayClassCastException
- if the value is not a Numberpublic Integer getInteger(int pos)
pos
in the array,pos
- the position in the arrayClassCastException
- if the value cannot be converted to Integerpublic Long getLong(int pos)
pos
in the array,pos
- the position in the arrayClassCastException
- if the value cannot be converted to Longpublic Double getDouble(int pos)
pos
in the array,pos
- the position in the arrayClassCastException
- if the value cannot be converted to Doublepublic Float getFloat(int pos)
pos
in the array,pos
- the position in the arrayClassCastException
- if the value cannot be converted to Floatpublic Boolean getBoolean(int pos)
pos
in the array,pos
- the position in the arrayClassCastException
- if the value cannot be converted to Integerpublic JsonObject getJsonObject(int pos)
pos
in the array.pos
- the position in the arrayClassCastException
- if the value cannot be converted to JsonObjectpublic JsonArray getJsonArray(int pos)
pos
in the array.pos
- the position in the arrayClassCastException
- if the value cannot be converted to JsonArraypublic byte[] getBinary(int pos)
pos
in the array.
JSON itself has no notion of a binary, so this method assumes there is a String value and
it contains a Base64 encoded binary, which it decodes if found and returns.pos
- the position in the arrayClassCastException
- if the value cannot be converted to StringIllegalArgumentException
- if the String value is not a legal Base64 encoded valuepublic Buffer getBuffer(int pos)
pos
in the array.
JSON itself has no notion of a binary, so this method assumes there is a String value and
it contains a Base64 encoded binary, which it decodes if found and returns.pos
- the position in the arrayClassCastException
- if the value cannot be converted to StringIllegalArgumentException
- if the String value is not a legal Base64 encoded valuepublic java.time.Instant getInstant(int pos)
pos
in the array.
JSON itself has no notion of a temporal types, this extension allows ISO 8601 string formatted dates with timezone
always set to zero UTC offset, as denoted by the suffix "Z" to be parsed as a instant value.
YYYY-MM-DDTHH:mm:ss.sssZ
is the default format used by web browser scripting. This extension complies to
the RFC-7493 with all the restrictions mentioned before. The method will then decode and return a instant value.pos
- the position in the arrayClassCastException
- if the value cannot be converted to Stringjava.time.format.DateTimeParseException
- if the String value is not a legal ISO 8601 encoded valuepublic Object getValue(int pos)
Map
will be wrapped to JsonObject
List
will be wrapped to JsonArray
Instant
will be converted to String
byte[]
will be converted to String
Buffer
will be converted to String
Enum
will be converted to String
pos
- the position in the arraypublic boolean hasNull(int pos)
pos
- the position in the arraypublic JsonArray addNull()
public JsonArray add(Object value)
value
- the valuepublic JsonArray add(int pos, Object value)
pos
.pos
- the positionvalue
- the valuepublic JsonArray addAll(JsonArray array)
array
- the arraypublic JsonArray setNull(int pos)
pos
.public JsonArray set(int pos, Object value)
pos
.pos
- position in the arrayvalue
- the valuepublic boolean contains(Object value)
value
- the valuepublic boolean remove(Object value)
value
- the value to removepublic Object remove(int pos)
pos
- the position to remove the value atJsonObject
is built from
this Map and returned. It the value is a List, a JsonArray
is built form this List and returned.public int size()
public boolean isEmpty()
public List getList()
List
as is.
This list may contain values that are not the types returned by the JsonArray
and
with an unpredictable representation of the value, e.g you might get a JSON object
as a JsonObject
or as a Map
.public JsonArray clear()
public String encode()
public Buffer toBuffer()
public String encodePrettily()
public JsonArray copy()
copy
in interface Shareable
IllegalStateException
- when a nested element cannot be copiedpublic JsonArray copy(java.util.function.Function<Object,?> cloner)
Unlike copy()
that can fail when an unknown element cannot be copied, this method
delegates the copy of such element to the cloner
function and will not fail.
cloner
- a function that copies custom values not supported by the JSON implementationpublic java.util.stream.Stream<Object> stream()
getValue(int)
, respecting the JSON requirements.
To stream the raw values, use the storage object stream instead:
jsonArray
.getList()
.stream()
public void writeToBuffer(Buffer buffer)
writeToBuffer
in interface io.vertx.core.shareddata.impl.ClusterSerializable
public int readFromBuffer(int pos, Buffer buffer)
readFromBuffer
in interface io.vertx.core.shareddata.impl.ClusterSerializable
Copyright © 2022 Eclipse. All rights reserved.