public class JsonArray extends Object implements Iterable<Object>, ClusterSerializable
Unlike some other languages Java does not have a native understanding of JSON. To enable JSON to be used easily in Vert.x code we use this class to encapsulate the notion of a JSON array.
Please see the documentation for more information.
Constructor and Description |
---|
JsonArray()
Create an empty instance
|
JsonArray(List list)
Create an instance from a List.
|
JsonArray(String json)
Create an instance from a String of JSON
|
Modifier and Type | Method and Description |
---|---|
JsonArray |
add(Boolean value)
Add a Boolean to the JSON array.
|
JsonArray |
add(byte[] value)
Add a binary value to the JSON array.
|
JsonArray |
add(CharSequence value)
Add a CharSequence to the JSON array.
|
JsonArray |
add(Double value)
Add a Double to the JSON array.
|
JsonArray |
add(Enum value)
Add an enum to the JSON array.
|
JsonArray |
add(Float value)
Add a Float to the JSON array.
|
JsonArray |
add(Integer value)
Add an Integer to the JSON array.
|
JsonArray |
add(JsonArray value)
Add another JSON array to the JSON array.
|
JsonArray |
add(JsonObject value)
Add a JSON object to the JSON array.
|
JsonArray |
add(Long value)
Add a Long to the JSON array.
|
JsonArray |
add(Object value)
Add an Object to the JSON array.
|
JsonArray |
add(String value)
Add a String 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()
Make a 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, |
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, |
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 unerlying List
|
Long |
getLong(int pos)
Get the Long 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 Object value at position
pos in the array. |
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.
|
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
|
String |
toString() |
void |
writeToBuffer(Buffer buffer) |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
public JsonArray(String json)
json
- the string of JSONpublic JsonArray()
public JsonArray(List list)
list
- public String getString(int pos)
pos
in the array,pos
- the position in the arrayClassCastException
- if the value cannot be converted to Stringpublic 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.
This method should be used in conjunction with add(byte[])
pos
- the position in the arrayClassCastException
- if the value cannot be converted to Stringpublic Object getValue(int pos)
pos
in the array.pos
- the position in the arraypublic boolean hasNull(int pos)
pos
- the position in the arraypublic JsonArray add(Enum value)
JSON has no concept of encoding Enums, so the Enum will be converted to a String using the Enum.name
method and the value added as a String.
value
- the valuepublic JsonArray add(CharSequence value)
value
- the valuepublic JsonArray add(String value)
value
- the valuepublic JsonArray add(Integer value)
value
- the valuepublic JsonArray add(Long value)
value
- the valuepublic JsonArray add(Double value)
value
- the valuepublic JsonArray add(Float value)
value
- the valuepublic JsonArray add(Boolean value)
value
- the valuepublic JsonArray addNull()
public JsonArray add(JsonObject value)
value
- the valuepublic JsonArray add(JsonArray value)
value
- the valuepublic JsonArray add(byte[] value)
JSON has no notion of binary so the binary will be base64 encoded to a String, and the String added.
value
- the valuepublic JsonArray add(Object value)
value
- the valuepublic JsonArray addAll(JsonArray array)
array
- the arraypublic 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 atpublic int size()
public boolean isEmpty()
public List getList()
public JsonArray clear()
public String encode()
public String encodePrettily()
public JsonArray copy()
public java.util.stream.Stream<Object> stream()
public void writeToBuffer(Buffer buffer)
writeToBuffer
in interface ClusterSerializable
public int readFromBuffer(int pos, Buffer buffer)
readFromBuffer
in interface ClusterSerializable
Copyright © 2015. All Rights Reserved.