public class JsonObject extends Object implements Iterable<Map.Entry<String,Object>>, io.vertx.core.shareddata.impl.ClusterSerializable, Shareable
| Constructor and Description | 
|---|
| JsonObject()Create a new, empty instance | 
| JsonObject(Buffer buf)Create an instance from a buffer. | 
| JsonObject(Map<String,Object> map)Create an instance from a Map. | 
| JsonObject(String json)Create an instance from a string of JSON | 
| Modifier and Type | Method and Description | 
|---|---|
| JsonObject | clear()Remove all the entries in this JSON object | 
| boolean | 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 objects | 
| byte[] | getBinary(String key)Get the binary value with the specified key. | 
| byte[] | getBinary(String key,
         byte[] def)Like  getBinary(String)but specifying a default value to return if there is no entry. | 
| Boolean | getBoolean(String key)Get the Boolean value with the specified key | 
| Boolean | getBoolean(String key,
          Boolean def)Like  getBoolean(String)but specifying a default value to return if there is no entry. | 
| Buffer | getBuffer(String key)Get the  Buffervalue with the specified key. | 
| Buffer | getBuffer(String key,
         Buffer def)Like  getBuffer(String)but specifying a default value to return if there is no entry. | 
| Double | getDouble(String key)Get the Double value with the specified key | 
| Double | getDouble(String key,
         Double def)Like  getDouble(String)but specifying a default value to return if there is no entry. | 
| Float | getFloat(String key)Get the Float value with the specified key | 
| Float | getFloat(String key,
        Float def)Like  getFloat(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)Like  getInstant(String)but specifying a default value to return if there is no entry. | 
| Integer | getInteger(String key)Get the Integer value with the specified key | 
| Integer | getInteger(String key,
          Integer def)Like  getInteger(String)but specifying a default value to return if there is no entry. | 
| JsonArray | getJsonArray(String key)Get the JsonArray value with the specified key | 
| JsonArray | getJsonArray(String key,
            JsonArray def)Like  getJsonArray(String)but specifying a default value to return if there is no entry. | 
| JsonObject | getJsonObject(String key)Get the JsonObject value with the specified key | 
| JsonObject | getJsonObject(String key,
             JsonObject def)Like  getJsonObject(String)but specifying a default value to return if there is no entry. | 
| Long | getLong(String key)Get the Long value with the specified key | 
| Long | getLong(String key,
       Long def)Like  getLong(String)but specifying a default value to return if there is no entry. | 
| Map<String,Object> | getMap()Get the underlying  Mapas is. | 
| Number | getNumber(String key)Get the Number value with the specified key | 
| Number | getNumber(String key,
         Number def)Like  getNumber(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 types  Instant,byte[]andEnumwhich can be converted to String. | 
| String | getString(String key,
         String def)Like  getString(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)Like  getValue(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. | 
| 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) | 
| Object | remove(String key)Remove an entry from this object. | 
| int | size()Get the number of entries in the JSON object | 
| java.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) | 
clone, finalize, getClass, notify, notifyAll, wait, wait, waitforEach, spliteratorpublic JsonObject(String json)
json - the string of JSONpublic JsonObject()
public JsonObject(Map<String,Object> map)
map - the map to create the instance from.public JsonObject(Buffer buf)
buf - the buffer to create the instance from.public static JsonObject mapFrom(Object obj)
null when obj is null.
obj - The object to convert to a JsonObject.IllegalArgumentException - if conversion fails due to an incompatible type.public <T> T mapTo(Class<T> type)
type - The type to instantiate from the JsonObject.IllegalArgumentException - if the type cannot be instantiated.public String getString(String key)
Instant,
 byte[] and Enum which can be converted to String.key - the key to return the value forpublic Number getNumber(String key)
key - the key to return the value forClassCastException - if the value is not a Numberpublic Integer getInteger(String key)
key - the key to return the value forClassCastException - if the value is not an Integerpublic Long getLong(String key)
key - the key to return the value forClassCastException - if the value is not a Longpublic Double getDouble(String key)
key - the key to return the value forClassCastException - if the value is not a Doublepublic Float getFloat(String key)
key - the key to return the value forClassCastException - if the value is not a Floatpublic Boolean getBoolean(String key)
key - the key to return the value forClassCastException - if the value is not a Booleanpublic JsonObject getJsonObject(String key)
key - the key to return the value forClassCastException - if the value is not a JsonObjectpublic JsonArray getJsonArray(String key)
key - the key to return the value forClassCastException - if the value is not a JsonArraypublic byte[] getBinary(String key)
key - the key to return the value forClassCastException - if the value is not a StringIllegalArgumentException - if the String value is not a legal Base64 encoded valuepublic Buffer getBuffer(String key)
Buffer 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.key - the string to return the value forClassCastException - if the value is not a stringIllegalArgumentException - if the value is not a legal Base64 encoded stringpublic java.time.Instant getInstant(String key)
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.key - the key to return the value forClassCastException - if the value is not a Stringjava.time.format.DateTimeParseException - if the String value is not a legal ISO 8601 encoded valuepublic Object getValue(String key)
Map will be wrapped to JsonObjectList will be wrapped to JsonArrayInstant will be converted to Stringbyte[] will be converted to StringEnum will be converted to Stringkey - the key to lookuppublic String getString(String key, String def)
getString(String) but specifying a default value to return if there is no entry.key - the key to lookupdef - the default value to use if the entry is not presentdef if no entry presentpublic Number getNumber(String key, Number def)
getNumber(String) but specifying a default value to return if there is no entry.key - the key to lookupdef - the default value to use if the entry is not presentdef if no entry presentpublic Integer getInteger(String key, Integer def)
getInteger(String) but specifying a default value to return if there is no entry.key - the key to lookupdef - the default value to use if the entry is not presentdef if no entry presentpublic Long getLong(String key, Long def)
getLong(String) but specifying a default value to return if there is no entry.key - the key to lookupdef - the default value to use if the entry is not presentdef if no entry presentpublic Double getDouble(String key, Double def)
getDouble(String) but specifying a default value to return if there is no entry.key - the key to lookupdef - the default value to use if the entry is not presentdef if no entry presentpublic Float getFloat(String key, Float def)
getFloat(String) but specifying a default value to return if there is no entry.key - the key to lookupdef - the default value to use if the entry is not presentdef if no entry presentpublic Boolean getBoolean(String key, Boolean def)
getBoolean(String) but specifying a default value to return if there is no entry.key - the key to lookupdef - the default value to use if the entry is not presentdef if no entry presentpublic JsonObject getJsonObject(String key, JsonObject def)
getJsonObject(String) but specifying a default value to return if there is no entry.key - the key to lookupdef - the default value to use if the entry is not presentdef if no entry presentpublic JsonArray getJsonArray(String key, JsonArray def)
getJsonArray(String) but specifying a default value to return if there is no entry.key - the key to lookupdef - the default value to use if the entry is not presentdef if no entry presentpublic byte[] getBinary(String key, byte[] def)
getBinary(String) but specifying a default value to return if there is no entry.key - the key to lookupdef - the default value to use if the entry is not presentdef if no entry presentpublic Buffer getBuffer(String key, Buffer def)
getBuffer(String) but specifying a default value to return if there is no entry.key - the key to lookupdef - the default value to use if the entry is not presentdef if no entry presentpublic java.time.Instant getInstant(String key, java.time.Instant def)
getInstant(String) but specifying a default value to return if there is no entry.key - the key to lookupdef - the default value to use if the entry is not presentdef if no entry presentpublic Object getValue(String key, Object def)
getValue(String) but specifying a default value to return if there is no entry.key - the key to lookupdef - the default value to use if the entry is not presentdef if no entry presentpublic boolean containsKey(String key)
key - the keypublic Set<String> fieldNames()
public JsonObject putNull(String key)
key - the keypublic JsonObject put(String key, Object value)
key - the keyvalue - the valuepublic Object remove(String key)
key - the keypublic JsonObject mergeIn(JsonObject other)
other - the other JSON objectpublic JsonObject mergeIn(JsonObject other, boolean deep)
other - the other JSON objectdeep - if true, a deep merge is performedpublic JsonObject mergeIn(JsonObject other, int depth)
other - the other JSON objectdepth - depth of mergepublic String encode()
public String encodePrettily()
public Buffer toBuffer()
public JsonObject copy()
copy in interface ShareableIllegalStateException - when a nested element cannot be copiedpublic JsonObject 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 Map<String,Object> getMap()
Map 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 a JsonObject or as a Map.public java.util.stream.Stream<Map.Entry<String,Object>> stream()
getValue(String), respecting the JSON requirements.
 To stream the raw values, use the storage object stream instead:
 
   jsonObject
     .getMap()
     .stream()
 public Iterator<Map.Entry<String,Object>> iterator()
public int size()
public JsonObject clear()
public boolean isEmpty()
public void writeToBuffer(Buffer buffer)
writeToBuffer in interface io.vertx.core.shareddata.impl.ClusterSerializablepublic int readFromBuffer(int pos,
                          Buffer buffer)
readFromBuffer in interface io.vertx.core.shareddata.impl.ClusterSerializableCopyright © 2022 Eclipse. All rights reserved.