public class JSONObject
extends java.util.LinkedHashMap<java.lang.String,java.lang.Object>
implements java.lang.reflect.InvocationHandler
| Modifier and Type | Class and Description |
|---|---|
(package private) static class |
JSONObject.NameConsumer
Consumer for processing method names.
|
| Modifier and Type | Field and Description |
|---|---|
(package private) static ObjectReader<JSONArray> |
arrayReader |
(package private) static long |
NONE_DIRECT_FEATURES |
private static long |
serialVersionUID |
| Constructor and Description |
|---|
JSONObject()
default
|
JSONObject(int initialCapacity) |
JSONObject(int initialCapacity,
float loadFactor) |
JSONObject(int initialCapacity,
float loadFactor,
boolean accessOrder) |
JSONObject(java.util.Map map) |
| Modifier and Type | Method and Description |
|---|---|
JSONObject |
clone() |
boolean |
containsKey(java.lang.Object key)
Returns true if this map contains a mapping for the specified key
|
boolean |
containsKey(java.lang.String key)
Returns true if this map contains a mapping for the specified key
|
void |
copyTo(java.lang.Object object,
JSONReader.Feature... features) |
java.lang.Object |
eval(JSONPath path)
Evaluates a JSONPath expression against this JSONObject.
|
JSONObject |
fluentPut(java.lang.String key,
java.lang.Object value)
Chained addition of elements
|
void |
forEachArrayObject(java.lang.String key,
java.util.function.Consumer<JSONObject> action)
Iterates over the JSONArray elements associated with the given key.
|
void |
forEchArrayObject(java.lang.String key,
java.util.function.Consumer<JSONObject> action)
Deprecated.
Typo in the method name. Use
forEachArrayObject instead |
static JSONObject |
from(java.lang.Object obj)
See
JSON.toJSON(java.lang.Object) for details |
static JSONObject |
from(java.lang.Object obj,
JSONWriter.Feature... writeFeatures)
See
JSON.toJSON(java.lang.Object) for details |
java.lang.Object |
get(java.lang.Object key)
Returns the Object of the associated keys in this
JSONObject. |
java.lang.Object |
get(java.lang.String key)
Returns the Object of the associated keys in this
JSONObject. |
java.math.BigDecimal |
getBigDecimal(java.lang.String key)
Returns the
BigDecimal of the associated keys in this JSONObject. |
java.math.BigInteger |
getBigInteger(java.lang.String key)
Returns the
BigInteger of the associated keys in this JSONObject. |
java.lang.Boolean |
getBoolean(java.lang.String key)
Returns the
Boolean of the associated keys in this JSONObject. |
boolean |
getBooleanValue(java.lang.String key)
Returns a boolean value of the associated key in this object.
|
boolean |
getBooleanValue(java.lang.String key,
boolean defaultValue)
Returns a boolean value of the associated key in this object.
|
java.lang.Object |
getByPath(java.lang.String jsonPath) |
java.lang.Byte |
getByte(java.lang.String key)
Returns the
Byte of the associated keys in this JSONObject. |
byte[] |
getBytes(java.lang.String key) |
byte |
getByteValue(java.lang.String key)
Returns a byte value of the associated keys in this
JSONObject. |
java.util.Date |
getDate(java.lang.String key)
Returns the
Date of the associated keys in this JSONObject. |
java.util.Date |
getDate(java.lang.String key,
java.util.Date defaultValue) |
java.lang.Double |
getDouble(java.lang.String key)
Returns the
Double of the associated keys in this JSONObject. |
double |
getDoubleValue(java.lang.String key)
Returns a double value of the associated keys in this
JSONObject. |
java.lang.Float |
getFloat(java.lang.String key)
Returns the
Float of the associated keys in this JSONObject. |
float |
getFloatValue(java.lang.String key)
Returns a float value of the associated keys in this
JSONObject. |
java.time.Instant |
getInstant(java.lang.String key)
Returns the
BigInteger of the associated keys in this JSONObject. |
java.lang.Integer |
getInteger(java.lang.String key)
Returns the
Integer of the associated keys in this JSONObject. |
int |
getIntValue(java.lang.String key)
Returns an int value of the associated keys in this
JSONObject. |
int |
getIntValue(java.lang.String key,
int defaultValue)
Returns an int value of the associated keys in this
JSONObject. |
JSONArray |
getJSONArray(java.lang.String key)
Returns the
JSONArray of the associated keys in this JSONObject. |
private java.lang.String |
getJSONFieldName(java.lang.reflect.Method method)
Gets the JSON field name from the method's annotations.
|
JSONObject |
getJSONObject(java.lang.String key)
Returns the
JSONObject of the associated keys in this JSONObject. |
<T> java.util.List<T> |
getList(java.lang.String key,
java.lang.Class<T> itemClass,
JSONReader.Feature... features)
Returns a list of objects of the specified type from the associated JSONArray in this
JSONObject. |
java.time.LocalDate |
getLocalDate(java.lang.String key) |
java.time.LocalDate |
getLocalDate(java.lang.String key,
java.time.LocalDate defaultValue) |
java.time.LocalDateTime |
getLocalDateTime(java.lang.String key) |
java.time.LocalDateTime |
getLocalDateTime(java.lang.String key,
java.time.LocalDateTime defaultValue) |
java.time.LocalTime |
getLocalTime(java.lang.String key) |
java.time.LocalTime |
getLocalTime(java.lang.String key,
java.time.LocalTime defaultValue) |
java.lang.Long |
getLong(java.lang.String key)
Returns the
Long of the associated keys in this JSONObject. |
long |
getLongValue(java.lang.String key)
Returns a long value of the associated keys in this
JSONObject. |
long |
getLongValue(java.lang.String key,
long defaultValue)
Returns a long value of the associated keys in this
JSONObject. |
<T> T |
getObject(java.lang.String key,
java.lang.Class<T> type,
JSONReader.Feature... features)
Returns the result of the
Type converter conversion of the associated value in this JSONObject. |
<T> T |
getObject(java.lang.String key,
java.util.function.Function<JSONObject,T> creator) |
<T> T |
getObject(java.lang.String key,
java.lang.reflect.Type type,
JSONReader.Feature... features)
Returns the result of the
Type converter conversion of the associated value in this JSONObject. |
<T> T |
getObject(java.lang.String key,
TypeReference<T> typeReference,
JSONReader.Feature... features)
Returns the result of the
Type converter conversion of the associated value in this JSONObject. |
java.time.OffsetDateTime |
getOffsetDateTime(java.lang.String key) |
java.time.OffsetDateTime |
getOffsetDateTime(java.lang.String key,
java.time.OffsetDateTime defaultValue) |
java.time.OffsetTime |
getOffsetTime(java.lang.String key) |
java.time.OffsetTime |
getOffsetTime(java.lang.String key,
java.time.OffsetTime defaultValue) |
java.lang.Object |
getOrDefault(java.lang.Object key,
java.lang.Object defaultValue) |
java.lang.Object |
getOrDefault(java.lang.String key,
java.lang.Object defaultValue) |
java.lang.Short |
getShort(java.lang.String key)
Returns the
Short of the associated keys in this JSONObject. |
short |
getShortValue(java.lang.String key)
Returns a short value of the associated keys in this
JSONObject. |
int |
getSize(java.lang.String key)
Returns the size of the value associated with the given key if it is a Map or Collection.
|
java.lang.String |
getString(java.lang.String key)
Returns the
String of the associated keys in this JSONObject. |
java.lang.String |
getString(java.lang.String key,
java.lang.String defaultValue)
Returns the
String of the associated keys in this JSONObject. |
java.time.ZonedDateTime |
getZonedDateTime(java.lang.String key) |
java.time.ZonedDateTime |
getZonedDateTime(java.lang.String key,
java.time.ZonedDateTime defaultValue) |
java.lang.Object |
invoke(java.lang.Object proxy,
java.lang.reflect.Method method,
java.lang.Object[] args)
Handles method invocations on a proxy instance.
|
boolean |
isArray(java.lang.Object key) |
boolean |
isValid(JSONSchema schema)
Checks if this JSONObject is valid according to the specified JSON schema.
|
(package private) static void |
nameFilter(java.lang.Iterable<?> iterable,
NameFilter nameFilter)
Applies a name filter to an iterable collection.
|
(package private) static void |
nameFilter(java.util.Map map,
NameFilter nameFilter)
Applies a name filter to a map.
|
void |
nameFilter(NameFilter nameFilter)
Applies a name filter to this JSONObject.
|
static JSONObject |
of()
JSONObject jsonObject = JSONObject.of();
|
private static JSONObject |
of(JSONObject jsonObject,
java.lang.Object... kvArray)
Pack multiple key-value pairs as
JSONObject |
static JSONObject |
of(java.lang.String key,
java.lang.Object value)
Pack a pair of key-values as
JSONObject |
static JSONObject |
of(java.lang.String k1,
java.lang.Object v1,
java.lang.String k2,
java.lang.Object v2)
Pack two key-value pairs as
JSONObject |
static JSONObject |
of(java.lang.String k1,
java.lang.Object v1,
java.lang.String k2,
java.lang.Object v2,
java.lang.String k3,
java.lang.Object v3)
Pack three key-value pairs as
JSONObject |
static JSONObject |
of(java.lang.String k1,
java.lang.Object v1,
java.lang.String k2,
java.lang.Object v2,
java.lang.String k3,
java.lang.Object v3,
java.lang.String k4,
java.lang.Object v4)
Pack three key-value pairs as
JSONObject |
static JSONObject |
of(java.lang.String k1,
java.lang.Object v1,
java.lang.String k2,
java.lang.Object v2,
java.lang.String k3,
java.lang.Object v3,
java.lang.String k4,
java.lang.Object v4,
java.lang.String k5,
java.lang.Object v5)
Pack three key-value pairs as
JSONObject |
static JSONObject |
of(java.lang.String k1,
java.lang.Object v1,
java.lang.String k2,
java.lang.Object v2,
java.lang.String k3,
java.lang.Object v3,
java.lang.String k4,
java.lang.Object v4,
java.lang.String k5,
java.lang.Object v5,
java.lang.Object... kvArray)
Pack multiple key-value pairs as
JSONObject |
static JSONObject |
parse(java.lang.String text,
JSONReader.Feature... features)
See
JSON.parse(java.lang.String) for details |
static JSONObject |
parseObject(java.lang.String text)
See
JSON.parseObject(java.lang.String) for details |
static <T> T |
parseObject(java.lang.String text,
java.lang.Class<T> objectClass)
See
JSON.parseObject(java.lang.String) for details |
static <T> T |
parseObject(java.lang.String text,
java.lang.Class<T> objectClass,
JSONReader.Feature... features)
See
JSON.parseObject(java.lang.String) for details |
static <T> T |
parseObject(java.lang.String text,
java.lang.reflect.Type objectType,
JSONReader.Feature... features)
See
JSON.parseObject(java.lang.String) for details |
static <T> T |
parseObject(java.lang.String text,
TypeReference<T> typeReference,
JSONReader.Feature... features)
See
JSON.parseObject(java.lang.String) for details |
JSONArray |
putArray(java.lang.String name)
Creates and puts a new JSONArray with the specified name.
|
JSONObject |
putObject(java.lang.String name)
Creates and puts a new JSONObject with the specified name.
|
<T> T |
to(java.lang.Class<T> clazz,
JSONReader.Feature... features)
Convert this
JSONObject to the specified Object |
<T> T |
to(java.util.function.Function<JSONObject,T> function) |
<T> T |
to(java.lang.reflect.Type type,
JSONReader.Feature... features)
Convert this
JSONObject to the specified Object |
<T> T |
to(TypeReference<T> typeReference,
JSONReader.Feature... features)
Convert this
JSONObject to the specified Object |
<T> T |
toJavaObject(java.lang.Class<T> clazz,
JSONReader.Feature... features)
Convert this
JSONObject to the specified Object |
<T> T |
toJavaObject(java.lang.reflect.Type type,
JSONReader.Feature... features)
Deprecated.
since 2.0.4, please use
to(Type, JSONReader.Feature...) |
<T> T |
toJavaObject(TypeReference<T> typeReference,
JSONReader.Feature... features)
Deprecated.
since 2.0.4, please use
to(Type, JSONReader.Feature...) |
byte[] |
toJSONBBytes(JSONWriter.Feature... features)
Serialize to JSONB bytes
|
java.lang.String |
toJSONString(JSONWriter.Feature... features)
Serialize to JSON
String |
static java.lang.String |
toJSONString(java.lang.Object object,
JSONWriter.Feature... features)
Serialize Java Object to JSON
String with specified JSONReader.Features enabled |
java.lang.String |
toString()
Serialize to JSON
String |
java.lang.String |
toString(JSONWriter.Feature... features)
Serialize to JSON
String |
(package private) static void |
valueFilter(java.lang.Iterable<?> iterable,
ValueFilter valueFilter)
Applies a value filter to an iterable collection.
|
(package private) static void |
valueFilter(java.util.Map map,
ValueFilter valueFilter)
Applies a value filter to a map.
|
void |
valueFilter(ValueFilter valueFilter)
Applies a value filter to this JSONObject.
|
clear, containsValue, entrySet, forEach, keySet, removeEldestEntry, replaceAll, valuescompute, computeIfAbsent, computeIfPresent, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, sizeprivate static final long serialVersionUID
static ObjectReader<JSONArray> arrayReader
static final long NONE_DIRECT_FEATURES
public JSONObject()
public JSONObject(int initialCapacity)
initialCapacity - the initial capacity = (number of elements to store / load factor) + 1java.lang.IllegalArgumentException - If the initial capacity is negativepublic JSONObject(int initialCapacity,
float loadFactor)
initialCapacity - the initial capacity = (number of elements to store / load factor) + 1loadFactor - the load factorjava.lang.IllegalArgumentException - If the initial capacity is negative or the load factor is negativepublic JSONObject(int initialCapacity,
float loadFactor,
boolean accessOrder)
initialCapacity - the initial capacity = (number of elements to store / load factor) + 1loadFactor - the load factoraccessOrder - the ordering mode - true for access-order, false for insertion-orderjava.lang.IllegalArgumentException - If the initial capacity is negative or the load factor is negativepublic JSONObject(java.util.Map map)
map - the map whose mappings are to be placed in this mapjava.lang.NullPointerException - If the specified map is nullpublic java.lang.Object get(java.lang.String key)
JSONObject.key - the key whose associated value is to be returnedpublic java.lang.Object get(java.lang.Object key)
JSONObject.get in interface java.util.Map<java.lang.String,java.lang.Object>get in class java.util.LinkedHashMap<java.lang.String,java.lang.Object>key - the key whose associated value is to be returnedpublic java.lang.Object getByPath(java.lang.String jsonPath)
public boolean containsKey(java.lang.String key)
key - the key whose presence in this map is to be testedpublic boolean containsKey(java.lang.Object key)
containsKey in interface java.util.Map<java.lang.String,java.lang.Object>containsKey in class java.util.HashMap<java.lang.String,java.lang.Object>key - the key whose presence in this map is to be testedpublic java.lang.Object getOrDefault(java.lang.String key,
java.lang.Object defaultValue)
key - the key whose associated value is to be returneddefaultValue - the default mapping of the keypublic java.lang.Object getOrDefault(java.lang.Object key,
java.lang.Object defaultValue)
getOrDefault in interface java.util.Map<java.lang.String,java.lang.Object>getOrDefault in class java.util.LinkedHashMap<java.lang.String,java.lang.Object>key - the key whose associated value is to be returneddefaultValue - the default mapping of the key@Deprecated
public void forEchArrayObject(java.lang.String key,
java.util.function.Consumer<JSONObject> action)
forEachArrayObject insteadkey - the key whose associated JSONArray is to be iteratedaction - the action to be performed for each JSONObject elementpublic void forEachArrayObject(java.lang.String key,
java.util.function.Consumer<JSONObject> action)
key - the key whose associated JSONArray is to be iteratedaction - the action to be performed for each JSONObject elementpublic JSONArray getJSONArray(java.lang.String key)
JSONArray of the associated keys in this JSONObject.key - the key whose associated value is to be returnedJSONArray or nullpublic <T> java.util.List<T> getList(java.lang.String key,
java.lang.Class<T> itemClass,
JSONReader.Feature... features)
JSONObject.T - the type of elements in the listkey - the key whose associated value is to be returneditemClass - the class of the items in the listfeatures - features to be enabled in parsingpublic JSONObject getJSONObject(java.lang.String key)
JSONObject of the associated keys in this JSONObject.key - the key whose associated value is to be returnedJSONObject or nullpublic java.lang.String getString(java.lang.String key)
String of the associated keys in this JSONObject.key - the key whose associated value is to be returnedString or nullpublic java.lang.String getString(java.lang.String key,
java.lang.String defaultValue)
String of the associated keys in this JSONObject.key - the key whose associated value is to be returneddefaultValue - the default mapping of the keyString or nullpublic java.lang.Double getDouble(java.lang.String key)
Double of the associated keys in this JSONObject.key - the key whose associated value is to be returnedDouble or nulljava.lang.NumberFormatException - If the value of get is String and it contains no parsable doubleJSONException - Unsupported type conversion to Doublepublic double getDoubleValue(java.lang.String key)
JSONObject.key - the key whose associated value is to be returnedjava.lang.NumberFormatException - If the value of get is String and it contains no parsable doubleJSONException - Unsupported type conversion to double valuepublic java.lang.Float getFloat(java.lang.String key)
Float of the associated keys in this JSONObject.key - the key whose associated value is to be returnedFloat or nulljava.lang.NumberFormatException - If the value of get is String and it contains no parsable floatJSONException - Unsupported type conversion to Floatpublic float getFloatValue(java.lang.String key)
JSONObject.key - the key whose associated value is to be returnedjava.lang.NumberFormatException - If the value of get is String and it contains no parsable floatJSONException - Unsupported type conversion to float valuepublic java.lang.Long getLong(java.lang.String key)
Long of the associated keys in this JSONObject.key - the key whose associated value is to be returnedLong or nulljava.lang.NumberFormatException - If the value of get is String and it contains no parsable longJSONException - Unsupported type conversion to Longpublic long getLongValue(java.lang.String key)
JSONObject.key - the key whose associated value is to be returnedjava.lang.NumberFormatException - If the value of get is String and it contains no parsable longJSONException - Unsupported type conversion to long valuepublic long getLongValue(java.lang.String key,
long defaultValue)
JSONObject.key - the key whose associated value is to be returneddefaultValue - the default mapping of the keyjava.lang.NumberFormatException - If the value of get is String and it contains no parsable longJSONException - Unsupported type conversion to long valuepublic java.lang.Integer getInteger(java.lang.String key)
Integer of the associated keys in this JSONObject.key - the key whose associated value is to be returnedInteger or nulljava.lang.NumberFormatException - If the value of get is String and it contains no parsable intJSONException - Unsupported type conversion to Integerpublic int getIntValue(java.lang.String key)
JSONObject.key - the key whose associated value is to be returnedjava.lang.NumberFormatException - If the value of get is String and it contains no parsable intJSONException - Unsupported type conversion to int valuepublic int getIntValue(java.lang.String key,
int defaultValue)
JSONObject.key - the key whose associated value is to be returneddefaultValue - the default mapping of the keyjava.lang.NumberFormatException - If the value of get is String and it contains no parsable intJSONException - Unsupported type conversion to int valuepublic java.lang.Short getShort(java.lang.String key)
Short of the associated keys in this JSONObject.key - the key whose associated value is to be returnedShort or nulljava.lang.NumberFormatException - If the value of get is String and it contains no parsable shortJSONException - Unsupported type conversion to Shortpublic short getShortValue(java.lang.String key)
JSONObject.key - the key whose associated value is to be returnedjava.lang.NumberFormatException - If the value of get is String and it contains no parsable shortJSONException - Unsupported type conversion to short valuepublic java.lang.Byte getByte(java.lang.String key)
Byte of the associated keys in this JSONObject.key - the key whose associated value is to be returnedByte or nulljava.lang.NumberFormatException - If the value of get is String and it contains no parsable byteJSONException - Unsupported type conversion to Bytepublic byte getByteValue(java.lang.String key)
JSONObject.key - the key whose associated value is to be returnedjava.lang.NumberFormatException - If the value of get is String and it contains no parsable byteJSONException - Unsupported type conversion to byte valuepublic byte[] getBytes(java.lang.String key)
public java.lang.Boolean getBoolean(java.lang.String key)
Boolean of the associated keys in this JSONObject.key - the key whose associated value is to be returnedBoolean or nullJSONException - Unsupported type conversion to Booleanpublic boolean getBooleanValue(java.lang.String key)
key - the key whose associated value is to be returnedJSONException - Unsupported type conversion to boolean valuepublic boolean getBooleanValue(java.lang.String key,
boolean defaultValue)
key - the key whose associated value is to be returneddefaultValue - the default mapping of the keyJSONException - Unsupported type conversion to boolean valuepublic java.math.BigInteger getBigInteger(java.lang.String key)
BigInteger of the associated keys in this JSONObject.key - the key whose associated value is to be returnedBigInteger or nullJSONException - Unsupported type conversion to BigIntegerjava.lang.NumberFormatException - If the value of get is String and it is not a valid representation of BigIntegerpublic java.math.BigDecimal getBigDecimal(java.lang.String key)
BigDecimal of the associated keys in this JSONObject.key - the key whose associated value is to be returnedBigDecimal or nullJSONException - Unsupported type conversion to BigDecimaljava.lang.NumberFormatException - If the value of get is String and it is not a valid representation of BigDecimalpublic java.util.Date getDate(java.lang.String key)
Date of the associated keys in this JSONObject.key - the key whose associated value is to be returnedDate or nullpublic java.util.Date getDate(java.lang.String key,
java.util.Date defaultValue)
public java.time.Instant getInstant(java.lang.String key)
BigInteger of the associated keys in this JSONObject.key - the key whose associated value is to be returnedBigInteger or nullpublic java.time.LocalDate getLocalDate(java.lang.String key)
public java.time.LocalDate getLocalDate(java.lang.String key,
java.time.LocalDate defaultValue)
public java.time.LocalTime getLocalTime(java.lang.String key)
public java.time.LocalTime getLocalTime(java.lang.String key,
java.time.LocalTime defaultValue)
public java.time.OffsetTime getOffsetTime(java.lang.String key)
public java.time.OffsetTime getOffsetTime(java.lang.String key,
java.time.OffsetTime defaultValue)
public java.time.LocalDateTime getLocalDateTime(java.lang.String key)
public java.time.LocalDateTime getLocalDateTime(java.lang.String key,
java.time.LocalDateTime defaultValue)
public java.time.OffsetDateTime getOffsetDateTime(java.lang.String key)
public java.time.OffsetDateTime getOffsetDateTime(java.lang.String key,
java.time.OffsetDateTime defaultValue)
public java.time.ZonedDateTime getZonedDateTime(java.lang.String key)
public java.time.ZonedDateTime getZonedDateTime(java.lang.String key,
java.time.ZonedDateTime defaultValue)
public java.lang.String toString()
StringtoString in class java.util.AbstractMap<java.lang.String,java.lang.Object>Stringpublic java.lang.String toString(JSONWriter.Feature... features)
Stringfeatures - features to be enabled in serializationStringpublic java.lang.String toJSONString(JSONWriter.Feature... features)
Stringfeatures - features to be enabled in serializationStringpublic static java.lang.String toJSONString(java.lang.Object object,
JSONWriter.Feature... features)
String with specified JSONReader.Features enabledobject - Java Object to be serialized into JSON Stringfeatures - features to be enabled in serializationpublic byte[] toJSONBBytes(JSONWriter.Feature... features)
features - features to be enabled in serializationpublic <T> T to(java.util.function.Function<JSONObject,T> function)
public <T> T to(java.lang.reflect.Type type,
JSONReader.Feature... features)
JSONObject to the specified Object
JSONObject obj = ...
Map<String, User> users = obj.to(new TypeReference<HashMap<String, User>>(){}.getType());
type - specify the Type to be convertedfeatures - features to be enabled in parsingpublic <T> T to(TypeReference<T> typeReference, JSONReader.Feature... features)
JSONObject to the specified Object
JSONObject obj = ...
Map<String, User> users = obj.to(new TypeReference<HashMap<String, User>>(){});
typeReference - specify the TypeReference to be convertedfeatures - features to be enabled in parsingpublic <T> T to(java.lang.Class<T> clazz,
JSONReader.Feature... features)
JSONObject to the specified Object
JSONObject obj = ...
User user = obj.to(User.class);
clazz - specify the Class<T> to be convertedfeatures - features to be enabled in parsingpublic void copyTo(java.lang.Object object,
JSONReader.Feature... features)
public <T> T toJavaObject(java.lang.Class<T> clazz,
JSONReader.Feature... features)
JSONObject to the specified Objectclazz - specify the Class<T> to be convertedfeatures - features to be enabled in parsingpublic <T> T toJavaObject(java.lang.reflect.Type type,
JSONReader.Feature... features)
to(Type, JSONReader.Feature...)JSONObject to the specified Objecttype - specify the Type to be convertedfeatures - features to be enabled in parsingpublic <T> T toJavaObject(TypeReference<T> typeReference, JSONReader.Feature... features)
to(Type, JSONReader.Feature...)JSONObject to the specified ObjecttypeReference - specify the TypeReference to be convertedfeatures - features to be enabled in parsingpublic <T> T getObject(java.lang.String key,
java.lang.Class<T> type,
JSONReader.Feature... features)
Type converter conversion of the associated value in this JSONObject.
User user = jsonObject.getObject("user", User.class);
key - the key whose associated value is to be returnedtype - specify the Class to be converted<T> or nullJSONException - If no suitable conversion method is foundpublic <T> T getObject(java.lang.String key,
java.lang.reflect.Type type,
JSONReader.Feature... features)
Type converter conversion of the associated value in this JSONObject.
User user = jsonObject.getObject("user", User.class);
key - the key whose associated value is to be returnedtype - specify the Type to be convertedfeatures - features to be enabled in parsing<T> or nullJSONException - If no suitable conversion method is foundpublic <T> T getObject(java.lang.String key,
TypeReference<T> typeReference,
JSONReader.Feature... features)
Type converter conversion of the associated value in this JSONObject.
User user = jsonObject.getObject("user", User.class);
key - the key whose associated value is to be returnedtypeReference - specify the TypeReference to be convertedfeatures - features to be enabled in parsing<T> or nullJSONException - If no suitable conversion method is foundpublic <T> T getObject(java.lang.String key,
java.util.function.Function<JSONObject,T> creator)
public java.lang.Object invoke(java.lang.Object proxy,
java.lang.reflect.Method method,
java.lang.Object[] args)
throws java.lang.Throwable
invoke in interface java.lang.reflect.InvocationHandlerproxy - proxy object, currently uselessmethod - methods that need reflectionargs - parameters of invokejava.lang.Throwable - if an error occurs during method invocationjava.lang.UnsupportedOperationException - If reflection for this method is not supportedjava.lang.ArrayIndexOutOfBoundsException - If the length of args does not match the length of the method parameterprivate java.lang.String getJSONFieldName(java.lang.reflect.Method method)
method - the method to get the JSON field name frompublic JSONArray putArray(java.lang.String name)
name - the name for the new JSONArraypublic JSONObject putObject(java.lang.String name)
name - the name for the new JSONObjectpublic JSONObject fluentPut(java.lang.String key, java.lang.Object value)
JSONObject object = new JSONObject().fluentPut("a", 1).fluentPut("b", 2).fluentPut("c", 3);
key - key with which the specified value is to be associatedvalue - value to be associated with the specified keypublic boolean isValid(JSONSchema schema)
schema - the JSON schema to validate againststatic void nameFilter(java.lang.Iterable<?> iterable,
NameFilter nameFilter)
iterable - the iterable collection to apply the filter tonameFilter - the name filter to applystatic void nameFilter(java.util.Map map,
NameFilter nameFilter)
map - the map to apply the filter tonameFilter - the name filter to applystatic void valueFilter(java.lang.Iterable<?> iterable,
ValueFilter valueFilter)
iterable - the iterable collection to apply the filter tovalueFilter - the value filter to applystatic void valueFilter(java.util.Map map,
ValueFilter valueFilter)
map - the map to apply the filter tovalueFilter - the value filter to applypublic void valueFilter(ValueFilter valueFilter)
valueFilter - the value filter to applypublic void nameFilter(NameFilter nameFilter)
nameFilter - the name filter to applypublic JSONObject clone()
clone in class java.util.HashMap<java.lang.String,java.lang.Object>JSONObject(Map)public java.lang.Object eval(JSONPath path)
path - the JSONPath expression to evaluateJSONPath.paths(Object)public int getSize(java.lang.String key)
key - the key whose associated value's size is to be returnedpublic static JSONObject of()
JSONObject jsonObject = JSONObject.of();
public static JSONObject of(java.lang.String key, java.lang.Object value)
JSONObject
JSONObject jsonObject = JSONObject.of("name", "fastjson2");
key - the key of the elementvalue - the value of the elementpublic static JSONObject of(java.lang.String k1, java.lang.Object v1, java.lang.String k2, java.lang.Object v2)
JSONObject
JSONObject jsonObject = JSONObject.of("key1", "value1", "key2", "value2");
k1 - first keyv1 - first valuek2 - second keyv2 - second valuepublic static JSONObject of(java.lang.String k1, java.lang.Object v1, java.lang.String k2, java.lang.Object v2, java.lang.String k3, java.lang.Object v3)
JSONObject
JSONObject jsonObject = JSONObject.of("key1", "value1", "key2", "value2", "key3", "value3");
k1 - first keyv1 - first valuek2 - second keyv2 - second valuek3 - third keyv3 - third valuepublic static JSONObject of(java.lang.String k1, java.lang.Object v1, java.lang.String k2, java.lang.Object v2, java.lang.String k3, java.lang.Object v3, java.lang.String k4, java.lang.Object v4)
JSONObject
JSONObject jsonObject = JSONObject.of("key1", "value1", "key2", "value2", "key3", "value3", "key4", "value4");
k1 - first keyv1 - first valuek2 - second keyv2 - second valuek3 - third keyv3 - third valuek4 - four keyv4 - four valuepublic static JSONObject of(java.lang.String k1, java.lang.Object v1, java.lang.String k2, java.lang.Object v2, java.lang.String k3, java.lang.Object v3, java.lang.String k4, java.lang.Object v4, java.lang.String k5, java.lang.Object v5)
JSONObject
JSONObject jsonObject = JSONObject.of("key1", "value1", "key2", "value2", "key3", "value3", "key4", "value4", "key5", "value5");
k1 - first keyv1 - first valuek2 - second keyv2 - second valuek3 - third keyv3 - third valuek4 - four keyv4 - four valuek5 - five keyv5 - five valuepublic static JSONObject of(java.lang.String k1, java.lang.Object v1, java.lang.String k2, java.lang.Object v2, java.lang.String k3, java.lang.Object v3, java.lang.String k4, java.lang.Object v4, java.lang.String k5, java.lang.Object v5, java.lang.Object... kvArray)
JSONObject
JSONObject jsonObject = JSONObject.of("key1", "value1", "key2", "value2", "key3", "value3", "key4", "value4", "key5", "value5", kvArray);
k1 - first keyv1 - first valuek2 - second keyv2 - second valuek3 - third keyv3 - third valuek4 - four keyv4 - four valuek5 - five keyv5 - five valuekvArray - multiple key-valueprivate static JSONObject of(JSONObject jsonObject, java.lang.Object... kvArray)
JSONObject
JSONObject jsonObject = JSONObject.of(Object... kvArray);
kvArray - key-valuepublic static <T> T parseObject(java.lang.String text,
java.lang.Class<T> objectClass)
JSON.parseObject(java.lang.String) for detailspublic static <T> T parseObject(java.lang.String text,
java.lang.Class<T> objectClass,
JSONReader.Feature... features)
JSON.parseObject(java.lang.String) for detailspublic static <T> T parseObject(java.lang.String text,
java.lang.reflect.Type objectType,
JSONReader.Feature... features)
JSON.parseObject(java.lang.String) for detailspublic static <T> T parseObject(java.lang.String text,
TypeReference<T> typeReference,
JSONReader.Feature... features)
JSON.parseObject(java.lang.String) for detailspublic static JSONObject parseObject(java.lang.String text)
JSON.parseObject(java.lang.String) for detailspublic static JSONObject parse(java.lang.String text, JSONReader.Feature... features)
JSON.parse(java.lang.String) for detailspublic static JSONObject from(java.lang.Object obj)
JSON.toJSON(java.lang.Object) for detailspublic static JSONObject from(java.lang.Object obj, JSONWriter.Feature... writeFeatures)
JSON.toJSON(java.lang.Object) for detailspublic boolean isArray(java.lang.Object key)