public final class JsonObject extends AbstractMap<String,JsonValue> implements JsonValue
Modifier and Type | Class and Description |
---|---|
static class |
JsonObject.Builder
Builds instances of
JsonObject from keys and values configured by put* methods. |
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
JsonValue.EntityType
Modifier and Type | Method and Description |
---|---|
JsonObject |
asJsonObject()
Returns this value as
JsonObject . |
static JsonObject.Builder |
builder()
Returns a
JsonObject.Builder . |
static Map.Entry<JsonString,JsonValue> |
entry(JsonString key,
JsonValue value)
|
static Map.Entry<String,JsonValue> |
entry(String key,
JsonValue value)
|
Set<Map.Entry<String,JsonValue>> |
entrySet()
Returns a
Set view of the JSON key-value mappings contained in this JSON object. |
boolean |
equals(Object otherObject)
Compares the specified object with this JSON object for equality.
|
JsonValue.EntityType |
getEntityType()
Returns
JsonValue.EntityType.OBJECT , which is the entity type of JsonObject . |
JsonValue[] |
getKeyValueArray()
Returns the key-value pairs as an array of
JsonValue . |
int |
hashCode()
Returns the hash code value for this JSON object.
|
static JsonObject |
of()
Returns a JSON object containing zero JSON key-value mapping.
|
static JsonObject |
of(JsonValue... keyValues)
Returns a JSON object containing an arbitrary number of JSON key-value mappings.
|
static JsonObject |
of(String k1,
JsonValue v1)
Returns a JSON object containing the specified single JSON key-value mapping.
|
static JsonObject |
of(String k1,
JsonValue v1,
String k2,
JsonValue v2)
Returns a JSON object containing the specified two JSON key-value mappings.
|
static JsonObject |
of(String k1,
JsonValue v1,
String k2,
JsonValue v2,
String k3,
JsonValue v3)
Returns a JSON object containing the specified three JSON key-value mappings.
|
static JsonObject |
of(String k1,
JsonValue v1,
String k2,
JsonValue v2,
String k3,
JsonValue v3,
String k4,
JsonValue v4)
Returns a JSON object containing the specified four JSON key-value mappings.
|
static JsonObject |
of(String k1,
JsonValue v1,
String k2,
JsonValue v2,
String k3,
JsonValue v3,
String k4,
JsonValue v4,
String k5,
JsonValue v5)
Returns a JSON object containing the specified five JSON key-value mappings.
|
static JsonObject |
of(String k1,
JsonValue v1,
String k2,
JsonValue v2,
String k3,
JsonValue v3,
String k4,
JsonValue v4,
String k5,
JsonValue v5,
String k6,
JsonValue v6)
Returns a JSON object containing the specified six JSON key-value mappings.
|
static JsonObject |
of(String k1,
JsonValue v1,
String k2,
JsonValue v2,
String k3,
JsonValue v3,
String k4,
JsonValue v4,
String k5,
JsonValue v5,
String k6,
JsonValue v6,
String k7,
JsonValue v7)
Returns a JSON object containing the specified seven JSON key-value mappings.
|
static JsonObject |
of(String k1,
JsonValue v1,
String k2,
JsonValue v2,
String k3,
JsonValue v3,
String k4,
JsonValue v4,
String k5,
JsonValue v5,
String k6,
JsonValue v6,
String k7,
JsonValue v7,
String k8,
JsonValue v8)
Returns a JSON object containing the specified eight JSON key-value mappings.
|
static JsonObject |
of(String k1,
JsonValue v1,
String k2,
JsonValue v2,
String k3,
JsonValue v3,
String k4,
JsonValue v4,
String k5,
JsonValue v5,
String k6,
JsonValue v6,
String k7,
JsonValue v7,
String k8,
JsonValue v8,
String k9,
JsonValue v9)
Returns a JSON object containing the specified nine JSON key-value mappings.
|
static JsonObject |
of(String k1,
JsonValue v1,
String k2,
JsonValue v2,
String k3,
JsonValue v3,
String k4,
JsonValue v4,
String k5,
JsonValue v5,
String k6,
JsonValue v6,
String k7,
JsonValue v7,
String k8,
JsonValue v8,
String k9,
JsonValue v9,
String k10,
JsonValue v10)
Returns a JSON object containing the specified ten JSON key-value mappings.
|
static JsonObject |
ofEntries(Map.Entry<String,JsonValue>... entries)
Returns a JSON object containing keys and values extracted from the given entries.
|
static JsonObject |
ofEntriesWithJsonStringKeys(Map.Entry<JsonString,JsonValue>... entries)
Returns a JSON object containing keys and values extracted from the given entries.
|
static JsonObject |
ofMap(Map<String,JsonValue> map)
Returns a JSON object containing keys and values extracted from the given
Map . |
static JsonObject |
ofMapWithJsonStringKeys(Map<JsonString,JsonValue> map)
Returns a JSON object containing keys and values extracted from the given
Map . |
static JsonObject |
ofUnsafe(String[] keys,
JsonValue[] values)
Returns a JSON object containing the specified arrays as its internal representation.
|
int |
presumeReferenceSizeInBytes()
Returns the approximate size of this JSON object in bytes presumed to occupy in
Page as a reference. |
int |
size()
Returns the number of JSON key-value mappings in this object.
|
String |
toJson()
Returns the stringified JSON representation of this JSON object.
|
Value |
toMsgpack()
Deprecated.
Do not use this method. It is to be removed at some point after Embulk v1.0.0.
It is here only to ensure a migration period from MessagePack-based JSON values to new
JSON values of
JsonValue . |
String |
toString()
Returns the string representation of this JSON object.
|
clear, clone, containsKey, containsValue, get, isEmpty, keySet, put, putAll, remove, values
finalize, getClass, notify, notifyAll, wait, wait, wait
asJsonArray, asJsonBoolean, asJsonDouble, asJsonLong, asJsonNull, asJsonString, fromMsgpack, isJsonArray, isJsonBoolean, isJsonDouble, isJsonLong, isJsonNull, isJsonObject, isJsonString
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
public static JsonObject of()
public static JsonObject of(String k1, JsonValue v1)
k1
- the mapping's key, not nullv1
- the mapping's value, not nullNullPointerException
- if the key or the value is null
public static JsonObject of(String k1, JsonValue v1, String k2, JsonValue v2)
k1
- the first mapping's key, not nullv1
- the first mapping's value, not nullk2
- the second mapping's key, not nullv2
- the second mapping's value, not nullNullPointerException
- if any key or any value is null
public static JsonObject of(String k1, JsonValue v1, String k2, JsonValue v2, String k3, JsonValue v3)
k1
- the first mapping's key, not nullv1
- the first mapping's value, not nullk2
- the second mapping's key, not nullv2
- the second mapping's value, not nullk3
- the third mapping's key, not nullv3
- the third mapping's value, not nullNullPointerException
- if any key or any value is null
public static JsonObject of(String k1, JsonValue v1, String k2, JsonValue v2, String k3, JsonValue v3, String k4, JsonValue v4)
k1
- the first mapping's key, not nullv1
- the first mapping's value, not nullk2
- the second mapping's key, not nullv2
- the second mapping's value, not nullk3
- the third mapping's key, not nullv3
- the third mapping's value, not nullk4
- the fourth mapping's key, not nullv4
- the fourth mapping's value, not nullNullPointerException
- if any key or any value is null
public static JsonObject of(String k1, JsonValue v1, String k2, JsonValue v2, String k3, JsonValue v3, String k4, JsonValue v4, String k5, JsonValue v5)
k1
- the first mapping's key, not nullv1
- the first mapping's value, not nullk2
- the second mapping's key, not nullv2
- the second mapping's value, not nullk3
- the third mapping's key, not nullv3
- the third mapping's value, not nullk4
- the fourth mapping's key, not nullv4
- the fourth mapping's value, not nullk5
- the fifth mapping's key, not nullv5
- the fifth mapping's value, not nullNullPointerException
- if any key or any value is null
public static JsonObject of(String k1, JsonValue v1, String k2, JsonValue v2, String k3, JsonValue v3, String k4, JsonValue v4, String k5, JsonValue v5, String k6, JsonValue v6)
k1
- the first mapping's key, not nullv1
- the first mapping's value, not nullk2
- the second mapping's key, not nullv2
- the second mapping's value, not nullk3
- the third mapping's key, not nullv3
- the third mapping's value, not nullk4
- the fourth mapping's key, not nullv4
- the fourth mapping's value, not nullk5
- the fifth mapping's key, not nullv5
- the fifth mapping's value, not nullk6
- the sixth mapping's key, not nullv6
- the sixth mapping's value, not nullNullPointerException
- if any key or any value is null
public static JsonObject of(String k1, JsonValue v1, String k2, JsonValue v2, String k3, JsonValue v3, String k4, JsonValue v4, String k5, JsonValue v5, String k6, JsonValue v6, String k7, JsonValue v7)
k1
- the first mapping's key, not nullv1
- the first mapping's value, not nullk2
- the second mapping's key, not nullv2
- the second mapping's value, not nullk3
- the third mapping's key, not nullv3
- the third mapping's value, not nullk4
- the fourth mapping's key, not nullv4
- the fourth mapping's value, not nullk5
- the fifth mapping's key, not nullv5
- the fifth mapping's value, not nullk6
- the sixth mapping's key, not nullv6
- the sixth mapping's value, not nullk7
- the seventh mapping's key, not nullv7
- the seventh mapping's value, not nullNullPointerException
- if any key or any value is null
public static JsonObject of(String k1, JsonValue v1, String k2, JsonValue v2, String k3, JsonValue v3, String k4, JsonValue v4, String k5, JsonValue v5, String k6, JsonValue v6, String k7, JsonValue v7, String k8, JsonValue v8)
k1
- the first mapping's key, not nullv1
- the first mapping's value, not nullk2
- the second mapping's key, not nullv2
- the second mapping's value, not nullk3
- the third mapping's key, not nullv3
- the third mapping's value, not nullk4
- the fourth mapping's key, not nullv4
- the fourth mapping's value, not nullk5
- the fifth mapping's key, not nullv5
- the fifth mapping's value, not nullk6
- the sixth mapping's key, not nullv6
- the sixth mapping's value, not nullk7
- the seventh mapping's key, not nullv7
- the seventh mapping's value, not nullk8
- the eighth mapping's key, not nullv8
- the eighth mapping's value, not nullNullPointerException
- if any key or any value is null
public static JsonObject of(String k1, JsonValue v1, String k2, JsonValue v2, String k3, JsonValue v3, String k4, JsonValue v4, String k5, JsonValue v5, String k6, JsonValue v6, String k7, JsonValue v7, String k8, JsonValue v8, String k9, JsonValue v9)
k1
- the first mapping's key, not nullv1
- the first mapping's value, not nullk2
- the second mapping's key, not nullv2
- the second mapping's value, not nullk3
- the third mapping's key, not nullv3
- the third mapping's value, not nullk4
- the fourth mapping's key, not nullv4
- the fourth mapping's value, not nullk5
- the fifth mapping's key, not nullv5
- the fifth mapping's value, not nullk6
- the sixth mapping's key, not nullv6
- the sixth mapping's value, not nullk7
- the seventh mapping's key, not nullv7
- the seventh mapping's value, not nullk8
- the eighth mapping's key, not nullv8
- the eighth mapping's value, not nullk9
- the ninth mapping's key, not nullv9
- the ninth mapping's value, not nullNullPointerException
- if any key or any value is null
public static JsonObject of(String k1, JsonValue v1, String k2, JsonValue v2, String k3, JsonValue v3, String k4, JsonValue v4, String k5, JsonValue v5, String k6, JsonValue v6, String k7, JsonValue v7, String k8, JsonValue v8, String k9, JsonValue v9, String k10, JsonValue v10)
k1
- the first mapping's key, not nullv1
- the first mapping's value, not nullk2
- the second mapping's key, not nullv2
- the second mapping's value, not nullk3
- the third mapping's key, not nullv3
- the third mapping's value, not nullk4
- the fourth mapping's key, not nullv4
- the fourth mapping's value, not nullk5
- the fifth mapping's key, not nullv5
- the fifth mapping's value, not nullk6
- the sixth mapping's key, not nullv6
- the sixth mapping's value, not nullk7
- the seventh mapping's key, not nullv7
- the seventh mapping's value, not nullk8
- the eighth mapping's key, not nullv8
- the eighth mapping's value, not nullk9
- the ninth mapping's key, not nullv9
- the ninth mapping's value, not nullk10
- the tenth mapping's key, not nullv10
- the tenth mapping's value, not nullNullPointerException
- if any key or any value is null
public static JsonObject of(JsonValue... keyValues)
Keys and values are specified as varargs. Even numbers of arguments must be specified. Where i as an
odd number, the i-th argument represents a key that must be JsonString
, and the i+1-th
argument represents a value for the key at the i-th argument.
keyValues
- the JSON keys and values to be contained in the JSON object, not nullIllegalArgumentException
- if odd numbers of arguments are specified, or non-JsonString
is specified as keyNullPointerException
- if any key or any value is null
@SafeVarargs public static JsonObject ofEntries(Map.Entry<String,JsonValue>... entries)
The specified entries themselves are not stored in the JSON object.
entries
- Map.Entry
s containing String
keys and JsonValue
values from which the JSON object is populated, not nullNullPointerException
- if the entries, any key or any value is null
@SafeVarargs public static JsonObject ofEntriesWithJsonStringKeys(Map.Entry<JsonString,JsonValue>... entries)
The specified entries themselves are not stored in the JSON object.
entries
- Map.Entry
s containing JsonString
keys and JsonValue
values from which the JSON object is populated, not nullNullPointerException
- if the entries, any key or any value is null
public static JsonObject ofMap(Map<String,JsonValue> map)
Map
.
The specified map itself is not stored in the JSON object.
map
- a Map
containing String
keys and JsonValue
values from which the JSON object is populated, not nullNullPointerException
- if the map, any key or any value is null
public static JsonObject ofMapWithJsonStringKeys(Map<JsonString,JsonValue> map)
Map
.
The specified map itself is not stored in the JSON object.
map
- a Map
containing JsonString
keys and JsonValue
values from which the JSON object is populated, not nullNullPointerException
- if the map, any key or any value is null
public static JsonObject ofUnsafe(String[] keys, JsonValue[] values)
This method is not safe. If the specified array is modified after creating a JsonObject
instance with this method, the created JsonObject
instance can unintentionally behave differently.
It has no null
checks. If either of the specified arrays is null
, or contains null
,
the created JsonObject
can behave unexpectedly.
keys
- the array of strings to be the internal representation as the keys in the new JsonObject
values
- the array of JSON values to be the internal representation as the values in the new JsonObject
public static JsonObject.Builder builder()
JsonObject.Builder
.JsonObject.Builder
public static Map.Entry<String,JsonValue> entry(String key, JsonValue value)
key
- the keyvalue
- the valueMap.Entry
public static Map.Entry<JsonString,JsonValue> entry(JsonString key, JsonValue value)
key
- the keyvalue
- the valueMap.Entry
public JsonValue.EntityType getEntityType()
JsonValue.EntityType.OBJECT
, which is the entity type of JsonObject
.getEntityType
in interface JsonValue
JsonValue.EntityType.OBJECT
, which is the entity type of JsonObject
public JsonObject asJsonObject()
JsonObject
.asJsonObject
in interface JsonValue
JsonObject
public int presumeReferenceSizeInBytes()
Page
as a reference.
This approximate size is used only as a threshold whether PageBuilder
is flushed, or not.
It is not accurate, it does not need to be accurate, and it is impossible in general to tell an accurate size that
a Java object occupies in the Java heap. But, a reasonable approximate would help to keep Page
performant in the Java heap.
It is better to flush more frequently for bigger JSON value objects, less often for smaller JSON value objects, but no infinite accumulation even for empty JSON value objects.
presumeReferenceSizeInBytes
in interface JsonValue
Page
as a referencepublic int size()
public Set<Map.Entry<String,JsonValue>> entrySet()
Set
view of the JSON key-value mappings contained in this JSON object.
This JSON object is unmodifiable, then the set is unmodifiable, too.
public JsonValue[] getKeyValueArray()
JsonValue
.
Odd elements are keys. Next element of an odd element is a value corresponding to the key.
For example, if this value represents {"k1": "v1", "k2": "v2"}
, this method returns ["k1", "v1", "k2", "v2"].public String toJson()
@Deprecated public Value toMsgpack()
JsonValue
.toMsgpack
in interface JsonValue
public String toString()
toString
in class AbstractMap<String,JsonValue>
public boolean equals(Object otherObject)
Note that it can return true
only when JsonObject
is given. It checks the equality as a JSON object.
It does not return true
for a general Map
even though the given map contains the same mapping.