Class JsonObject
- java.lang.Object
-
- io.vertx.core.json.JsonObject
-
public class JsonObject extends Object implements Iterable<Map.Entry<String,Object>>, ClusterSerializable, Shareable
A representation of a JSON object in Java. 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 object. The implementation adheres to the RFC-7493 to support Temporal data types as well as binary data. Please see the documentation for more information.- Author:
- Tim Fox
-
-
Constructor Summary
Constructors Constructor Description JsonObject()
Create a new, empty instanceJsonObject(Buffer buf)
Create an instance from a buffer.JsonObject(String json)
Create an instance from a string of JSONJsonObject(Map<String,Object> map)
Create an instance from a Map.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description JsonObject
clear()
Remove all the entries in this JSON objectboolean
containsKey(String key)
Does the JSON object contain the specified key?JsonObject
copy()
Deep copy of this JSON object.JsonObject
copy(java.util.function.Function<Object,?> cloner)
Deep copy of this JSON object.String
encode()
Encode this JSON object as a string.String
encodePrettily()
Encode this JSON object a a string, with whitespace to make the object easier to read by a human, or other sentient organism.boolean
equals(Object o)
Set<String>
fieldNames()
Return the set of field names in the JSON objectsbyte[]
getBinary(String key)
Get the binary value with the specified key.byte[]
getBinary(String key, byte[] def)
LikegetBinary(String)
but specifying a default value to return if there is no entry.Boolean
getBoolean(String key)
Get the Boolean value with the specified keyBoolean
getBoolean(String key, Boolean def)
LikegetBoolean(String)
but specifying a default value to return if there is no entry.Buffer
getBuffer(String key)
Get theBuffer
value with the specified key.Buffer
getBuffer(String key, Buffer def)
LikegetBuffer(String)
but specifying a default value to return if there is no entry.Double
getDouble(String key)
Get the Double value with the specified keyDouble
getDouble(String key, Double def)
LikegetDouble(String)
but specifying a default value to return if there is no entry.Float
getFloat(String key)
Get the Float value with the specified keyFloat
getFloat(String key, Float def)
LikegetFloat(String)
but specifying a default value to return if there is no entry.java.time.Instant
getInstant(String key)
Get the instant value with the specified key.java.time.Instant
getInstant(String key, java.time.Instant def)
LikegetInstant(String)
but specifying a default value to return if there is no entry.Integer
getInteger(String key)
Get the Integer value with the specified keyInteger
getInteger(String key, Integer def)
LikegetInteger(String)
but specifying a default value to return if there is no entry.JsonArray
getJsonArray(String key)
Get the JsonArray value with the specified keyJsonArray
getJsonArray(String key, JsonArray def)
LikegetJsonArray(String)
but specifying a default value to return if there is no entry.JsonObject
getJsonObject(String key)
Get the JsonObject value with the specified keyJsonObject
getJsonObject(String key, JsonObject def)
LikegetJsonObject(String)
but specifying a default value to return if there is no entry.Long
getLong(String key)
Get the Long value with the specified keyLong
getLong(String key, Long def)
LikegetLong(String)
but specifying a default value to return if there is no entry.Map<String,Object>
getMap()
Get the underlyingMap
as is.Number
getNumber(String key)
Get the Number value with the specified keyNumber
getNumber(String key, Number def)
LikegetNumber(String)
but specifying a default value to return if there is no entry.String
getString(String key)
Get the string value with the specified key, special cases are addressed for extended JSON typesInstant
,byte[]
andEnum
which can be converted to String.String
getString(String key, String def)
LikegetString(String)
but specifying a default value to return if there is no entry.Object
getValue(String key)
Get the value with the specified key, as an Object with types respecting the limitations of JSON.Object
getValue(String key, Object def)
LikegetValue(String)
but specifying a default value to return if there is no entry.int
hashCode()
boolean
isEmpty()
Is this object entry?Iterator<Map.Entry<String,Object>>
iterator()
Get an Iterator of the entries in the JSON object.static JsonObject
mapFrom(Object obj)
Create a JsonObject from the fields of a Java object.<T> T
mapTo(Class<T> type)
Instantiate a Java object from a JsonObject.JsonObject
mergeIn(JsonObject other)
Merge in another JSON object.JsonObject
mergeIn(JsonObject other, boolean deep)
Merge in another JSON object.JsonObject
mergeIn(JsonObject other, int depth)
Merge in another JSON object.static JsonObject
of()
Create a JsonObject containing zero mappings.static JsonObject
of(String k1, Object v1)
Create a JsonObject containing a single mapping.static JsonObject
of(String k1, Object v1, String k2, Object v2)
Create a JsonObject containing two mappings.static JsonObject
of(String k1, Object v1, String k2, Object v2, String k3, Object v3)
Create a JsonObject containing three mappings.static JsonObject
of(String k1, Object v1, String k2, Object v2, String k3, Object v3, String k4, Object v4)
Create a JsonObject containing four mappings.static JsonObject
of(String k1, Object v1, String k2, Object v2, String k3, Object v3, String k4, Object v4, String k5, Object v5)
Create a JsonObject containing five mappings.static JsonObject
of(String k1, Object v1, String k2, Object v2, String k3, Object v3, String k4, Object v4, String k5, Object v5, String k6, Object v6)
Create a JsonObject containing six mappings.static JsonObject
of(String k1, Object v1, String k2, Object v2, String k3, Object v3, String k4, Object v4, String k5, Object v5, String k6, Object v6, String k7, Object v7)
Create a JsonObject containing seven mappings.static JsonObject
of(String k1, Object v1, String k2, Object v2, String k3, Object v3, String k4, Object v4, String k5, Object v5, String k6, Object v6, String k7, Object v7, String k8, Object v8)
Create a JsonObject containing eight mappings.static JsonObject
of(String k1, Object v1, String k2, Object v2, String k3, Object v3, String k4, Object v4, String k5, Object v5, String k6, Object v6, String k7, Object v7, String k8, Object v8, String k9, Object v9)
Create a JsonObject containing nine mappings.static JsonObject
of(String k1, Object v1, String k2, Object v2, String k3, Object v3, String k4, Object v4, String k5, Object v5, String k6, Object v6, String k7, Object v7, String k8, Object v8, String k9, Object v9, String k10, Object v10)
Create a JsonObject containing ten mappings.JsonObject
put(String key, Object value)
Put an Object into the JSON object with the specified key.JsonObject
putNull(String key)
Put a null value into the JSON object with the specified key.int
readFromBuffer(int pos, Buffer buffer)
Method invoked when deserializing bytes to this instance.Object
remove(String key)
Remove an entry from this object.int
size()
Get the number of entries in the JSON objectjava.util.stream.Stream<Map.Entry<String,Object>>
stream()
Get a Stream over the entries in the JSON object.Buffer
toBuffer()
Encode this JSON object as buffer.String
toString()
void
writeToBuffer(Buffer buffer)
Method invoked when serializing this instance.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
JsonObject
public JsonObject(String json)
Create an instance from a string of JSON- Parameters:
json
- the string of JSON
-
JsonObject
public JsonObject()
Create a new, empty instance
-
JsonObject
public JsonObject(Map<String,Object> map)
Create an instance from a Map. The Map is not copied.- Parameters:
map
- the map to create the instance from.
-
JsonObject
public JsonObject(Buffer buf)
Create an instance from a buffer.- Parameters:
buf
- the buffer to create the instance from.
-
-
Method Detail
-
of
public static JsonObject of()
Create a JsonObject containing zero mappings.- Returns:
- an empty JsonObject.
-
of
public static JsonObject of(String k1, Object v1)
Create a JsonObject containing a single mapping.- Parameters:
k1
- the mapping's keyv1
- the mapping's value- Returns:
- a JsonObject containing the specified mapping.
-
of
public static JsonObject of(String k1, Object v1, String k2, Object v2)
Create a JsonObject containing two mappings.- Parameters:
k1
- the first mapping's keyv1
- the first mapping's valuek2
- the second mapping's keyv2
- the second mapping's value- Returns:
- a JsonObject containing the specified mappings.
-
of
public static JsonObject of(String k1, Object v1, String k2, Object v2, String k3, Object v3)
Create a JsonObject containing three mappings.- Parameters:
k1
- the first mapping's keyv1
- the first mapping's valuek2
- the second mapping's keyv2
- the second mapping's valuek3
- the third mapping's keyv3
- the third mapping's value- Returns:
- a JsonObject containing the specified mappings.
-
of
public static JsonObject of(String k1, Object v1, String k2, Object v2, String k3, Object v3, String k4, Object v4)
Create a JsonObject containing four mappings.- Parameters:
k1
- the first mapping's keyv1
- the first mapping's valuek2
- the second mapping's keyv2
- the second mapping's valuek3
- the third mapping's keyv3
- the third mapping's valuek4
- the fourth mapping's keyv4
- the fourth mapping's value- Returns:
- a JsonObject containing the specified mappings.
-
of
public static JsonObject of(String k1, Object v1, String k2, Object v2, String k3, Object v3, String k4, Object v4, String k5, Object v5)
Create a JsonObject containing five mappings.- Parameters:
k1
- the first mapping's keyv1
- the first mapping's valuek2
- the second mapping's keyv2
- the second mapping's valuek3
- the third mapping's keyv3
- the third mapping's valuek4
- the fourth mapping's keyv4
- the fourth mapping's valuek5
- the fifth mapping's keyv5
- the fifth mapping's value- Returns:
- a JsonObject containing the specified mappings.
-
of
public static JsonObject of(String k1, Object v1, String k2, Object v2, String k3, Object v3, String k4, Object v4, String k5, Object v5, String k6, Object v6)
Create a JsonObject containing six mappings.- Parameters:
k1
- the first mapping's keyv1
- the first mapping's valuek2
- the second mapping's keyv2
- the second mapping's valuek3
- the third mapping's keyv3
- the third mapping's valuek4
- the fourth mapping's keyv4
- the fourth mapping's valuek5
- the fifth mapping's keyv5
- the fifth mapping's valuek6
- the sixth mapping's keyv6
- the sixth mapping's value- Returns:
- a JsonObject containing the specified mappings.
-
of
public static JsonObject of(String k1, Object v1, String k2, Object v2, String k3, Object v3, String k4, Object v4, String k5, Object v5, String k6, Object v6, String k7, Object v7)
Create a JsonObject containing seven mappings.- Parameters:
k1
- the first mapping's keyv1
- the first mapping's valuek2
- the second mapping's keyv2
- the second mapping's valuek3
- the third mapping's keyv3
- the third mapping's valuek4
- the fourth mapping's keyv4
- the fourth mapping's valuek5
- the fifth mapping's keyv5
- the fifth mapping's valuek6
- the sixth mapping's keyv6
- the sixth mapping's valuek7
- the seventh mapping's keyv7
- the seventh mapping's value- Returns:
- a JsonObject containing the specified mappings.
-
of
public static JsonObject of(String k1, Object v1, String k2, Object v2, String k3, Object v3, String k4, Object v4, String k5, Object v5, String k6, Object v6, String k7, Object v7, String k8, Object v8)
Create a JsonObject containing eight mappings.- Parameters:
k1
- the first mapping's keyv1
- the first mapping's valuek2
- the second mapping's keyv2
- the second mapping's valuek3
- the third mapping's keyv3
- the third mapping's valuek4
- the fourth mapping's keyv4
- the fourth mapping's valuek5
- the fifth mapping's keyv5
- the fifth mapping's valuek6
- the sixth mapping's keyv6
- the sixth mapping's valuek7
- the seventh mapping's keyv7
- the seventh mapping's valuek8
- the eighth mapping's keyv8
- the eighth mapping's value- Returns:
- a JsonObject containing the specified mappings.
-
of
public static JsonObject of(String k1, Object v1, String k2, Object v2, String k3, Object v3, String k4, Object v4, String k5, Object v5, String k6, Object v6, String k7, Object v7, String k8, Object v8, String k9, Object v9)
Create a JsonObject containing nine mappings.- Parameters:
k1
- the first mapping's keyv1
- the first mapping's valuek2
- the second mapping's keyv2
- the second mapping's valuek3
- the third mapping's keyv3
- the third mapping's valuek4
- the fourth mapping's keyv4
- the fourth mapping's valuek5
- the fifth mapping's keyv5
- the fifth mapping's valuek6
- the sixth mapping's keyv6
- the sixth mapping's valuek7
- the seventh mapping's keyv7
- the seventh mapping's valuek8
- the eighth mapping's keyv8
- the eighth mapping's valuek9
- the ninth mapping's keyv9
- the ninth mapping's value- Returns:
- a JsonObject containing the specified mappings.
-
of
public static JsonObject of(String k1, Object v1, String k2, Object v2, String k3, Object v3, String k4, Object v4, String k5, Object v5, String k6, Object v6, String k7, Object v7, String k8, Object v8, String k9, Object v9, String k10, Object v10)
Create a JsonObject containing ten mappings.- Parameters:
k1
- the first mapping's keyv1
- the first mapping's valuek2
- the second mapping's keyv2
- the second mapping's valuek3
- the third mapping's keyv3
- the third mapping's valuek4
- the fourth mapping's keyv4
- the fourth mapping's valuek5
- the fifth mapping's keyv5
- the fifth mapping's valuek6
- the sixth mapping's keyv6
- the sixth mapping's valuek7
- the seventh mapping's keyv7
- the seventh mapping's valuek8
- the eighth mapping's keyv8
- the eighth mapping's valuek9
- the ninth mapping's keyv9
- the ninth mapping's valuek10
- the tenth mapping's keyv10
- the tenth mapping's value- Returns:
- a JsonObject containing the specified mappings.
-
mapFrom
public static JsonObject mapFrom(Object obj)
Create a JsonObject from the fields of a Java object. Faster than calling `new JsonObject(Json.encode(obj))`.null when
obj
isnull
.- Parameters:
obj
- The object to convert to a JsonObject.- Throws:
IllegalArgumentException
- if conversion fails due to an incompatible type.
-
mapTo
public <T> T mapTo(Class<T> type)
Instantiate a Java object from a JsonObject. Faster than calling `Json.decodeValue(Json.encode(jsonObject), type)`.- Parameters:
type
- The type to instantiate from the JsonObject.- Throws:
IllegalArgumentException
- if the type cannot be instantiated.
-
getString
public String getString(String key)
Get the string value with the specified key, special cases are addressed for extended JSON typesInstant
,byte[]
andEnum
which can be converted to String.- Parameters:
key
- the key to return the value for- Returns:
- the value string representation or null if no value for that key
-
getNumber
public Number getNumber(String key)
Get the Number value with the specified key- Parameters:
key
- the key to return the value for- Returns:
- the value or null if no value for that key
- Throws:
ClassCastException
- if the value is not a Number
-
getInteger
public Integer getInteger(String key)
Get the Integer value with the specified key- Parameters:
key
- the key to return the value for- Returns:
- the value or null if no value for that key
- Throws:
ClassCastException
- if the value is not an Integer
-
getLong
public Long getLong(String key)
Get the Long value with the specified key- Parameters:
key
- the key to return the value for- Returns:
- the value or null if no value for that key
- Throws:
ClassCastException
- if the value is not a Long
-
getDouble
public Double getDouble(String key)
Get the Double value with the specified key- Parameters:
key
- the key to return the value for- Returns:
- the value or null if no value for that key
- Throws:
ClassCastException
- if the value is not a Double
-
getFloat
public Float getFloat(String key)
Get the Float value with the specified key- Parameters:
key
- the key to return the value for- Returns:
- the value or null if no value for that key
- Throws:
ClassCastException
- if the value is not a Float
-
getBoolean
public Boolean getBoolean(String key)
Get the Boolean value with the specified key- Parameters:
key
- the key to return the value for- Returns:
- the value or null if no value for that key
- Throws:
ClassCastException
- if the value is not a Boolean
-
getJsonObject
public JsonObject getJsonObject(String key)
Get the JsonObject value with the specified key- Parameters:
key
- the key to return the value for- Returns:
- the value or null if no value for that key
- Throws:
ClassCastException
- if the value is not a JsonObject
-
getJsonArray
public JsonArray getJsonArray(String key)
Get the JsonArray value with the specified key- Parameters:
key
- the key to return the value for- Returns:
- the value or null if no value for that key
- Throws:
ClassCastException
- if the value is not a JsonArray
-
getBinary
public byte[] getBinary(String key)
Get the binary value with the specified key.JSON itself has no notion of a binary, this extension complies to the RFC-7493, so this method assumes there is a String value with the key and it contains a Base64 encoded binary, which it decodes if found and returns.
- Parameters:
key
- the key to return the value for- Returns:
- the value or null if no value for that key
- Throws:
ClassCastException
- if the value is not a StringIllegalArgumentException
- if the String value is not a legal Base64 encoded value
-
getBuffer
public Buffer getBuffer(String key)
Get theBuffer
value with the specified key.JSON itself has no notion of a binary, this extension complies to the RFC-7493, so this method assumes there is a String value with the key and it contains a Base64 encoded binary, which it decodes if found and returns.
- Parameters:
key
- the string to return the value for- Returns:
- the value or null if no value for that key
- Throws:
ClassCastException
- if the value is not a stringIllegalArgumentException
- if the value is not a legal Base64 encoded string
-
getInstant
public java.time.Instant getInstant(String key)
Get the instant value with the specified key.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.- Parameters:
key
- the key to return the value for- Returns:
- the value or null if no value for that key
- Throws:
ClassCastException
- if the value is not a Stringjava.time.format.DateTimeParseException
- if the String value is not a legal ISO 8601 encoded value
-
getValue
public Object getValue(String key)
Get the value with the specified key, as an Object with types respecting the limitations of JSON.Map
will be wrapped toJsonObject
List
will be wrapped toJsonArray
Instant
will be converted toString
byte[]
will be converted toString
Enum
will be converted toString
- Parameters:
key
- the key to lookup- Returns:
- the value
-
getString
public String getString(String key, String def)
LikegetString(String)
but specifying a default value to return if there is no entry.- Parameters:
key
- the key to lookupdef
- the default value to use if the entry is not present- Returns:
- the value or
def
if no entry present
-
getNumber
public Number getNumber(String key, Number def)
LikegetNumber(String)
but specifying a default value to return if there is no entry.- Parameters:
key
- the key to lookupdef
- the default value to use if the entry is not present- Returns:
- the value or
def
if no entry present
-
getInteger
public Integer getInteger(String key, Integer def)
LikegetInteger(String)
but specifying a default value to return if there is no entry.- Parameters:
key
- the key to lookupdef
- the default value to use if the entry is not present- Returns:
- the value or
def
if no entry present
-
getLong
public Long getLong(String key, Long def)
LikegetLong(String)
but specifying a default value to return if there is no entry.- Parameters:
key
- the key to lookupdef
- the default value to use if the entry is not present- Returns:
- the value or
def
if no entry present
-
getDouble
public Double getDouble(String key, Double def)
LikegetDouble(String)
but specifying a default value to return if there is no entry.- Parameters:
key
- the key to lookupdef
- the default value to use if the entry is not present- Returns:
- the value or
def
if no entry present
-
getFloat
public Float getFloat(String key, Float def)
LikegetFloat(String)
but specifying a default value to return if there is no entry.- Parameters:
key
- the key to lookupdef
- the default value to use if the entry is not present- Returns:
- the value or
def
if no entry present
-
getBoolean
public Boolean getBoolean(String key, Boolean def)
LikegetBoolean(String)
but specifying a default value to return if there is no entry.- Parameters:
key
- the key to lookupdef
- the default value to use if the entry is not present- Returns:
- the value or
def
if no entry present
-
getJsonObject
public JsonObject getJsonObject(String key, JsonObject def)
LikegetJsonObject(String)
but specifying a default value to return if there is no entry.- Parameters:
key
- the key to lookupdef
- the default value to use if the entry is not present- Returns:
- the value or
def
if no entry present
-
getJsonArray
public JsonArray getJsonArray(String key, JsonArray def)
LikegetJsonArray(String)
but specifying a default value to return if there is no entry.- Parameters:
key
- the key to lookupdef
- the default value to use if the entry is not present- Returns:
- the value or
def
if no entry present
-
getBinary
public byte[] getBinary(String key, byte[] def)
LikegetBinary(String)
but specifying a default value to return if there is no entry.- Parameters:
key
- the key to lookupdef
- the default value to use if the entry is not present- Returns:
- the value or
def
if no entry present
-
getBuffer
public Buffer getBuffer(String key, Buffer def)
LikegetBuffer(String)
but specifying a default value to return if there is no entry.- Parameters:
key
- the key to lookupdef
- the default value to use if the entry is not present- Returns:
- the value or
def
if no entry present
-
getInstant
public java.time.Instant getInstant(String key, java.time.Instant def)
LikegetInstant(String)
but specifying a default value to return if there is no entry.- Parameters:
key
- the key to lookupdef
- the default value to use if the entry is not present- Returns:
- the value or
def
if no entry present
-
getValue
public Object getValue(String key, Object def)
LikegetValue(String)
but specifying a default value to return if there is no entry.- Parameters:
key
- the key to lookupdef
- the default value to use if the entry is not present- Returns:
- the value or
def
if no entry present
-
containsKey
public boolean containsKey(String key)
Does the JSON object contain the specified key?- Parameters:
key
- the key- Returns:
- true if it contains the key, false if not.
-
fieldNames
public Set<String> fieldNames()
Return the set of field names in the JSON objects- Returns:
- the set of field names
-
putNull
public JsonObject putNull(String key)
Put a null value into the JSON object with the specified key.- Parameters:
key
- the key- Returns:
- a reference to this, so the API can be used fluently
-
put
public JsonObject put(String key, Object value)
Put an Object into the JSON object with the specified key.- Parameters:
key
- the keyvalue
- the value- Returns:
- a reference to this, so the API can be used fluently
-
remove
public Object remove(String key)
Remove an entry from this object.- Parameters:
key
- the key- Returns:
- the value that was removed, or null if none
-
mergeIn
public JsonObject mergeIn(JsonObject other)
Merge in another JSON object.This is the equivalent of putting all the entries of the other JSON object into this object. This is not a deep merge, entries containing (sub) JSON objects will be replaced entirely.
- Parameters:
other
- the other JSON object- Returns:
- a reference to this, so the API can be used fluently
-
mergeIn
public JsonObject mergeIn(JsonObject other, boolean deep)
Merge in another JSON object. A deep merge (recursive) matches (sub) JSON objects in the existing tree and replaces all matching entries. JsonArrays are treated like any other entry, i.e. replaced entirely.- Parameters:
other
- the other JSON objectdeep
- if true, a deep merge is performed- Returns:
- a reference to this, so the API can be used fluently
-
mergeIn
public JsonObject mergeIn(JsonObject other, int depth)
Merge in another JSON object. The merge is deep (recursive) to the specified level. If depth is 0, no merge is performed, if depth is greater than the depth of one of the objects, a full deep merge is performed.- Parameters:
other
- the other JSON objectdepth
- depth of merge- Returns:
- a reference to this, so the API can be used fluently
-
encode
public String encode()
Encode this JSON object as a string.- Returns:
- the string encoding.
-
encodePrettily
public String encodePrettily()
Encode this JSON object a a string, with whitespace to make the object easier to read by a human, or other sentient organism.- Returns:
- the pretty string encoding.
-
toBuffer
public Buffer toBuffer()
Encode this JSON object as buffer.- Returns:
- the buffer encoding.
-
copy
public JsonObject copy()
Deep copy of this JSON object.- Specified by:
copy
in interfaceShareable
- Returns:
- a copy where all elements have been copied recursively
- Throws:
IllegalStateException
- when a nested element cannot be copied
-
copy
public JsonObject copy(java.util.function.Function<Object,?> cloner)
Deep copy of this JSON object.Unlike
copy()
that can fail when an unknown element cannot be copied, this method delegates the copy of such element to thecloner
function and will not fail.- Parameters:
cloner
- a function that copies custom values not supported by the JSON implementation- Returns:
- a copy where all elements have been copied recursively
-
getMap
public Map<String,Object> getMap()
Get the underlyingMap
as is.This map may contain values that are not the types returned by the
JsonObject
and with an unpredictable representation of the value, e.g you might get a JSON object as aJsonObject
or as aMap
.- Returns:
- the underlying Map.
-
stream
public java.util.stream.Stream<Map.Entry<String,Object>> stream()
Get a Stream over the entries in the JSON object. The values in the stream will follow the same rules as defined ingetValue(String)
, respecting the JSON requirements.To stream the raw values, use the storage object stream instead:
jsonObject .getMap() .stream()
- Returns:
- a Stream
-
iterator
public Iterator<Map.Entry<String,Object>> iterator()
Get an Iterator of the entries in the JSON object.
-
size
public int size()
Get the number of entries in the JSON object- Returns:
- the number of entries
-
clear
public JsonObject clear()
Remove all the entries in this JSON object
-
isEmpty
public boolean isEmpty()
Is this object entry?- Returns:
- true if it has zero entries, false if not.
-
writeToBuffer
public void writeToBuffer(Buffer buffer)
Description copied from interface:ClusterSerializable
Method invoked when serializing this instance.- Specified by:
writeToBuffer
in interfaceClusterSerializable
- Parameters:
buffer
- theBuffer
where the serialized bytes must be written to
-
readFromBuffer
public int readFromBuffer(int pos, Buffer buffer)
Description copied from interface:ClusterSerializable
Method invoked when deserializing bytes to this instance.- Specified by:
readFromBuffer
in interfaceClusterSerializable
- Parameters:
pos
- the position where to start reading thebuffer
buffer
- theBuffer
where the serialized bytes must be read from- Returns:
- the position after the last serialized byte
-
-