package org.json;
/*
Public Domain.
*/
import java.io.IOException;
import java.io.Writer;
import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
/**
* A JSONObject is an unordered collection of name/value pairs. Its external form is a string
* wrapped in curly braces with colons between the names and values, and commas between the values
* and names. The internal form is an object having get and opt methods
* for accessing the values by name, and put methods for adding or replacing values by
* name. The values can be any of these types: Boolean, JSONArray,
* JSONObject, Number, String, or the
* JSONObject.NULL object. A JSONObject constructor can be used to convert an external
* form JSON text into an internal form whose values can be retrieved with the get and
* opt methods, or to convert values into a JSON text using the put and
* toString methods. A get method returns a value if one can be found, and
* throws an exception if one cannot be found. An opt method returns a default value
* instead of throwing an exception, and so is useful for obtaining optional values.
*
* The generic get() and opt() methods return an object, which you can
* cast or query for type. There are also typed get and opt methods that
* do type checking and type coercion for you. The opt methods differ from the get methods in that
* they do not throw. Instead, they return a specified value, such as null.
*
* The put methods add or replace values in an object. For example,
*
*
* myString = new JSONObject()
* .put("JSON", "Hello, World!").toString();
*
*
* produces the string {"JSON": "Hello, World"}.
*
* The texts produced by the toString methods strictly conform to the JSON syntax
* rules. The constructors are more forgiving in the texts they will accept:
*
*
An extra , (comma) may appear just before the closing
* brace.
*
Strings may be quoted with ' (single quote).
*
Strings do not need to be quoted at all if they do not begin with a quote or single quote,
* and if they do not contain leading or trailing spaces, and if they do not contain any of these
* characters: { } [ ] / \ : , # and if they do not look like numbers and if they are
* not the reserved words true, false, or null.
*
*
* @author JSON.org
* @version 2016-08-15
*/
public class JSONObject extends JSONBase {
/**
* The map where the JSONObject's properties are kept.
*/
private final Map map;
//TODO: Remove dead code
/*
* Retrieves the type of the underlying Map in this class.
*
* @return The class object representing the type of the underlying Map.
*/
//TODO: Remove dead code
/*
public Class extends Map> getMapType() {
return map.getClass();
}
*/
/**
* Construct an empty JSONObject.
*/
public JSONObject() {
// HashMap is used on purpose to ensure that elements are unordered by the specification.
// JSON tends to be a portable transfer format to allows the container implementations to
// rearrange their items for a faster element retrieval based on associative access.
// Therefore, an implementation mustn't rely on the order of the item.
this.map = new HashMap();
}
/**
* Construct a JSONObject from a subset of another JSONObject. An array of strings is used to
* identify the keys that should be copied. Missing keys are ignored.
*
* @param jo A JSONObject.
* @param names An array of strings.
*/
public JSONObject(JSONObject jo, String ... names) {
this(names.length);
for (String name : names) {
try {
this.putOnce(name, jo.opt(name));
}
catch (Exception ignore) { // exception thrown for missing key
}
}
}
/**
* Construct a JSONObject from a JSONTokener.
*
* @param jtok A JSONTokener object containing the source string.
* @throws JSONException If there is a syntax error in the source string or a duplicated key.
*/
public JSONObject(JSONTokener jtok) throws JSONException {
this(jtok, jtok.getJsonParserConfiguration());
}
/**
* Construct a JSONObject from a JSONTokener with custom json parse configurations. The supplied
* configuration applies to all values during construction, including nested objects and arrays. The
* tokener's original configuration is restored afterward, even if parsing fails.
*
* @param jtok A JSONTokener object containing the source string.
* @param pconfig Variable to pass parser custom configuration for json parsing.
* @throws JSONException If there is a syntax error in the source string or a duplicated key.
*/
public JSONObject(JSONTokener jtok, JSONParserConfiguration pconfig) throws JSONException {
this(jtok, pconfig, true);
}
/**
* Construct a JSONObject from a JSONTokener with custom json parse configurations, for internal
* use. Never call this instead of using withStrictMode(boolean).
*
* @param jtok A JSONTokener object containing the source string.
* @param pconfig Variable to pass parser custom configuration for json parsing.
* @param isInitial A boolean that determines whether this object is the root.
* @throws JSONException If there is a syntax error in the source string or a duplicated key.
*/
JSONObject(JSONTokener jtok, JSONParserConfiguration pconfig, boolean isInitial)
throws JSONException {
this();
JSONParserConfiguration originalConfiguration = jtok.getJsonParserConfiguration();
jtok.setJsonParserConfigurationInternal(pconfig);
try {
if (jtok.nextClean() != '{') {
throw jtok.syntaxError("A JSONObject text must begin with '{'");
}
for (;;) {
if (parseJSONObject(jtok, pconfig, isInitial)) {
return;
}
}
}
finally {
jtok.setJsonParserConfigurationInternal(originalConfiguration);
}
}
/**
* Parses entirety of JSON object
*
* @param jtok Parses text as tokens
* @param pconfig Variable to pass parser custom configuration for json parsing.
* @param isInitial True if start of document, else false
* @return True if done building object, else false
*/
private boolean parseJSONObject(
JSONTokener jtok, JSONParserConfiguration pconfig, boolean isInitial) {
Object obj;
String key;
boolean doneParsing = false;
char c = jtok.nextClean();
switch (c) {
case 0:
throw jtok.syntaxError("A JSONObject text must end with '}'");
case '}':
if (isInitial && pconfig.isStrictMode() && jtok.nextClean() != 0) {
throw jtok.syntaxError("Strict mode error: Unparsed characters found at end " +
"of input text");
}
return true;
default:
obj = jtok.nextSimpleValue(c);
key = obj.toString();
}
checkKeyForStrictMode(jtok, pconfig, obj);
// The key is followed by ':'.
c = jtok.nextClean();
if (c != ':') {
throw jtok.syntaxError("Expected a ':' after a key");
}
// Use syntaxError(..) to include error location
if (key != null) {
// Check if key exists
boolean keyExists = this.opt(key) != null;
if (keyExists && !pconfig.isOverwriteDuplicateKey()) {
throw jtok.syntaxError("Duplicate key \"" + key + "\"");
}
Object value = jtok.nextValue();
// Only add value if non-null
if (value != null) {
this.put(key, value);
}
}
// Pairs are separated by ','.
if (parseEndOfKeyValuePair(jtok, pconfig, isInitial)) {
doneParsing = true;
}
return doneParsing;
}
/**
* Checks for valid end of key:value pair
* @param jtok Parses text as tokens
* @param pconfig Variable to pass parser custom configuration for json parsing.
* @param isInitial True if end of JSON object, else false
* @return True if end of JSON object, else false
*/
private static boolean parseEndOfKeyValuePair(
JSONTokener jtok, JSONParserConfiguration pconfig, boolean isInitial) {
switch (jtok.nextClean()) {
case ';':
// In strict mode semicolon is not a valid separator
if (pconfig.isStrictMode()) {
throw jtok.syntaxError("Strict mode error: Invalid character ';' found");
}
break;
case ',':
if (jtok.nextClean() == '}') {
// trailing commas are not allowed in strict mode
if (pconfig.isStrictMode()) {
throw jtok.syntaxError(
"Strict mode error: Expected another object element");
}
// End of JSON object
return true;
}
if (jtok.end()) {
throw jtok.syntaxError("A JSONObject text must end with '}'");
}
jtok.back();
break;
case '}':
if (isInitial && pconfig.isStrictMode() && jtok.nextClean() != 0) {
throw jtok.syntaxError(
"Strict mode error: Unparsed characters found at end of input text");
}
// End of JSON object
return true;
default:
throw jtok.syntaxError("Expected a ',' or '}'");
}
// Not at end of JSON object
return false;
}
/**
* Throws error if key violates strictMode
* @param jtok Parses text as tokens
* @param pconfig Variable to pass parser custom configuration for json parsing.
* @param obj Value to be checked
*/
private static void checkKeyForStrictMode(
JSONTokener jtok, JSONParserConfiguration pconfig, Object obj) {
if (pconfig != null && pconfig.isStrictMode()) {
if(obj instanceof Boolean) {
throw jtok.syntaxError(String.format(
"Strict mode error: key '%s' cannot be boolean", obj.toString()));
}
if(obj == Null.TYPE) {
throw jtok.syntaxError(String.format(
"Strict mode error: key '%s' cannot be null", obj.toString()));
}
if(obj instanceof Number) {
throw jtok.syntaxError(String.format(
"Strict mode error: key '%s' cannot be number", obj.toString()));
}
}
}
/**
* Construct a JSONObject from a Map.
*
* @param m A map object that can be used to initialize the contents of
* the JSONObject.
* @throws JSONException If a value in the map is non-finite number.
* @throws NullPointerException If a key in the map is null
*/
public JSONObject(Map, ?> m) {
this(m, 0, new JSONParserConfiguration());
}
/**
* Construct a JSONObject from a Map with custom json parse configurations.
*
* @param m A map object that can be used to initialize the contents of the JSONObject.
* @param pconfig Variable to pass parser custom configuration for json parsing.
*/
public JSONObject(Map, ?> m, JSONParserConfiguration pconfig) {
this(m, 0, pconfig);
}
/**
* Construct a JSONObject from a map with recursion depth.
*/
public JSONObject(Map, ?> m, int recursionDepth, JSONParserConfiguration pconfig) {
if (recursionDepth > pconfig.getMaxNestingDepth()) {
throw new JSONException(
"JSONObject has reached recursion depth limit of " + pconfig.getMaxNestingDepth());
}
if (m == null) {
this.map = new HashMap();
}
else {
this.map = new HashMap(m.size());
for (final Entry, ?> e : m.entrySet()) {
if(e.getKey() == null) {
throw new NullPointerException("Null key.");
}
final Object value = e.getValue();
if (value != null || pconfig.isUseNativeNulls()) {
JSONUtils.testValidity(value);
this.map.put(String.valueOf(e.getKey()),
wrapper.wrap(value, recursionDepth + 1, pconfig));
}
}
}
}
/**
* Construct a JSONObject from a source JSON text string. This is the most commonly used JSONObject
* constructor.
*
* @param source A string beginning with { (left brace) and ending
* with } (right brace).
* @exception JSONException If there is a syntax error in the source string or a duplicated key.
*/
public JSONObject(String source) throws JSONException {
this(source, new JSONParserConfiguration());
}
/**
* Construct a JSONObject from a source JSON text string with custom json parse configurations.
* This is the most commonly used JSONObject constructor.
*
* @param source A string beginning with { (left brace) and ending
* with } (right brace).
* @param pconfig Variable to pass parser custom configuration for json parsing.
* @exception JSONException If there is a syntax error in the source string or a duplicated key.
*/
public JSONObject(String source, JSONParserConfiguration pconfig) throws JSONException {
this(new JSONTokener(source, pconfig), pconfig);
}
/**
* Constructor to specify an initial capacity of the internal map. Useful for library internal calls
* where we know, or at least can best guess, how big this JSONObject will be.
*
* @param initialCapacity initial capacity of the internal map.
*/
protected JSONObject(int initialCapacity){
this.map = new HashMap(initialCapacity);
}
/**
* Accumulate values under a key. It is similar to the put method except that if there is already an
* object stored under the key then a JSONArray is stored under the key to hold all of the
* accumulated values. If there is already a JSONArray, then the new value is appended to it. In
* contrast, the put method replaces the previous value.
*
* If only one value is accumulated that is not a JSONArray, then the result will be the same as
* using put. But if multiple values are accumulated, then the result will be like append.
*
* @param key A key string.
* @param value An object to be accumulated under the key.
* @return this.
* @throws JSONException If the value is non-finite number.
* @throws NullPointerException If the key is null.
*/
public JSONObject accumulate(String key, Object value) throws JSONException {
JSONUtils.testValidity(value);
Object object = this.opt(key);
if (object == null) {
this.put(key,
value instanceof JSONArray ? new JSONArray().put(value) : value);
}
else if (object instanceof JSONArray) {
((JSONArray) object).put(value);
}
else {
this.put(key, new JSONArray().put(object).put(value));
}
return this;
}
/**
* Append values to the array under a key. If the key does not exist in the JSONObject, then the key
* is put in the JSONObject with its value being a * JSONArray containing the value parameter. If
* the key was already associated with a JSONArray, then the value parameter is appended to it.
*
* @param key A key string.
* @param value An object to be accumulated under the key.
* @return this.
* @throws JSONException If the value is non-finite number or if the current value associated with
* the key is not a JSONArray.
* @throws NullPointerException If the key is null.
*/
public JSONObject append(String key, Object value) throws JSONException {
JSONUtils.testValidity(value);
Object object = this.opt(key);
if (object == null) {
this.put(key, new JSONArray().put(value));
} else if (object instanceof JSONArray) {
this.put(key, ((JSONArray) object).put(value));
} else {
throw wrongValueFormatException(key, "JSONArray", null, null);
}
return this;
}
/**
* Produce a string from a double. The string "null" will be returned if the number is not finite.
*
* @param d A double.
* @return A String.
*/
public static String doubleToString(double d) {
if (Double.isInfinite(d) || Double.isNaN(d)) {
return "null";
}
// Shave off trailing zeros and decimal point, if possible.
String string = Double.toString(d);
// idx = 0 case is covered by behavior of Double.toString()
if (string.indexOf('.') > 0 && string.indexOf('e') < 0
&& string.indexOf('E') < 0) {
while (string.endsWith("0")) {
string = string.substring(0, string.length() - 1);
}
if (string.endsWith(".")) {
string = string.substring(0, string.length() - 1);
}
}
return string;
}
/**
* Get the value object associated with a key.
*
* @param key A key string.
* @return The object associated with the key.
* @throws JSONException if the key is not found.
*/
public Object get(String key) throws JSONException {
if (key == null) {
throw new JSONException("Null key.");
}
Object object = this.opt(key);
if (object == null) {
throw new JSONException("JSONObject[" + JSONUtils.quote(key) + "] not found.");
}
return object;
}
/**
* Get the enum value associated with a key.
*
* @param Enum Type
* @param clazz The type of enum to retrieve.
* @param key A key string.
* @return The enum value associated with the key
* @throws JSONException if the key is not found or if the value cannot be converted to an enum.
*/
public > E getEnum(Class clazz, String key) throws JSONException {
E val = optEnum(clazz, key);
if(val==null) {
// JSONException should really take a throwable argument.
// If it did, I would re-implement this with the Enum.valueOf
// method and place any thrown exception in the JSONException
throw wrongValueFormatException(key, "enum of type "
+ JSONUtils.quote(clazz.getSimpleName()), opt(key), null);
}
return val;
}
/**
* Get the boolean value associated with a key.
*
* @param key A key string.
* @return The truth.
* @throws JSONException if the value is not a Boolean or the String "true" or "false".
*/
public boolean getBoolean(String key) throws JSONException {
Object object = this.get(key);
if (Boolean.FALSE.equals(object)
|| (object instanceof String && "false".equalsIgnoreCase((String) object))) {
return false;
} else if (Boolean.TRUE.equals(object)
|| (object instanceof String && "true".equalsIgnoreCase((String) object))) {
return true;
}
throw wrongValueFormatException(key, "Boolean", object, null);
}
/**
* Get the BigInteger value associated with a key.
*
* @param key A key string.
* @return The numeric value.
* @throws JSONException if the key is not found or if the value cannot be converted to BigInteger.
*/
public BigInteger getBigInteger(String key) throws JSONException {
return this.getBigInteger(key, new JSONParserConfiguration());
}
/**
* Get the BigInteger value associated with a key.
*
* @param key A key string.
* @param pconfig A configuration whose {@code maxNumberLength} bounds the number of decimal digits
* in the returned integer. Values exceeding this length are treated as unconvertible. Pass a
* configuration with {@link ParserConfiguration#UNDEFINED_MAXIMUM_NUMBER_LENGTH} to disable this
* check.
*
* @return The numeric value.
* @throws JSONException if the key is not found or if the value cannot be converted to BigInteger.
*/
public BigInteger getBigInteger(String key, JSONParserConfiguration pconfig)
throws JSONException {
Object object = this.get(key);
BigInteger ret = JSONUtils.objectToBigInteger(object, null, pconfig);
if (ret != null) {
return ret;
}
throw wrongValueFormatException(key, "BigInteger", object, null);
}
/**
* Get the BigDecimal value associated with a key. If the value is float or double, the
* {@link BigDecimal#BigDecimal(double)} constructor will be used. See notes on the constructor for
* conversion issues that may arise.
*
* @param key A key string.
* @return The numeric value.
* @throws JSONException if the key is not found or if the value cannot be converted to BigDecimal.
*/
public BigDecimal getBigDecimal(String key) throws JSONException {
Object object = this.get(key);
BigDecimal ret = JSONUtils.objectToBigDecimal(object, null);
if (ret != null) {
return ret;
}
throw wrongValueFormatException(key, "BigDecimal", object, null);
}
/**
* Get the double value associated with a key.
*
* @param key A key string.
* @return The numeric value.
* @throws JSONException if the key is not found or if the value is not a Number object and cannot
* be converted to a number.
*/
public double getDouble(String key) throws JSONException {
final Object object = this.get(key);
if(object instanceof Number) {
return ((Number)object).doubleValue();
}
try {
return Double.parseDouble(object.toString());
}
catch (Exception e) {
throw wrongValueFormatException(key, "double", object, e);
}
}
/**
* Get the float value associated with a key.
*
* @param key A key string.
* @return The numeric value.
* @throws JSONException if the key is not found or if the value is not a Number object and cannot
* be converted to a number.
*/
public float getFloat(String key) throws JSONException {
final Object object = this.get(key);
if(object instanceof Number) {
return ((Number)object).floatValue();
}
try {
return Float.parseFloat(object.toString());
}
catch (Exception e) {
throw wrongValueFormatException(key, "float", object, e);
}
}
/**
* Get the Number value associated with a key.
*
* @param key A key string.
* @return The numeric value.
* @throws JSONException if the key is not found or if the value is not a Number object and cannot
* be converted to a number.
*/
public Number getNumber(String key) throws JSONException {
Object object = this.get(key);
try {
if (object instanceof Number) {
return (Number)object;
}
return JSONUtils.stringToNumber(object.toString());
}
catch (Exception e) {
throw wrongValueFormatException(key, "number", object, e);
}
}
/**
* Get the int value associated with a key.
*
* @param key A key string.
* @return The integer value.
* @throws JSONException if the key is not found or if the value cannot be converted to an integer.
*/
public int getInt(String key) throws JSONException {
final Object object = this.get(key);
if(object instanceof Number) {
return ((Number)object).intValue();
}
try {
return Integer.parseInt(object.toString());
}
catch (Exception e) {
throw wrongValueFormatException(key, "int", object, e);
}
}
/**
* Get the JSONArray value associated with a key.
*
* @param key A key string.
* @return A JSONArray which is the value.
* @throws JSONException if the key is not found or if the value is not a JSONArray.
*/
public JSONArray getJSONArray(String key) throws JSONException {
Object object = this.get(key);
if (object instanceof JSONArray) {
return (JSONArray) object;
}
throw wrongValueFormatException(key, "JSONArray", object, null);
}
/**
* Get the JSONObject value associated with a key.
*
* @param key A key string.
* @return A JSONObject which is the value.
* @throws JSONException if the key is not found or if the value is not a JSONObject.
*/
public JSONObject getJSONObject(String key) throws JSONException {
Object object = this.get(key);
if (object instanceof JSONObject) {
return (JSONObject) object;
}
throw wrongValueFormatException(key, "JSONObject", object, null);
}
/**
* Get the long value associated with a key.
*
* @param key A key string.
* @return The long value.
* @throws JSONException if the key is not found or if the value cannot be converted to a long.
*/
public long getLong(String key) throws JSONException {
final Object object = this.get(key);
if(object instanceof Number) {
return ((Number)object).longValue();
}
try {
return Long.parseLong(object.toString());
}
catch (Exception e) {
throw wrongValueFormatException(key, "long", object, e);
}
}
/**
* Get an array of field names from a JSONObject.
*
* @param jo JSON object
* @return An array of field names, or null if there are no names.
*/
public static String[] getNames(JSONObject jo) {
if (jo.isEmpty()) {
return null;
}
return jo.keySet().toArray(new String[jo.length()]);
}
/**
* Get an array of public field names from an Object.
*
* @param object object to read
* @return An array of field names, or null if there are no names.
*/
public static String[] getNames(Object object) {
if (object == null) {
return null;
}
Class> klass = object.getClass();
Field[] fields = klass.getFields();
int length = fields.length;
if (length == 0) {
return null;
}
String[] names = new String[length];
for (int i = 0; i < length; i += 1) {
names[i] = fields[i].getName();
}
return names;
}
/**
* Get the string associated with a key.
*
* @param key A key string.
* @return A string which is the value.
* @throws JSONException if there is no string value for the key.
*/
public String getString(String key) throws JSONException {
Object object = this.get(key);
if (object instanceof String) {
return (String) object;
}
throw wrongValueFormatException(key, "string", object, null);
}
/**
* Determine if the JSONObject contains a specific key.
*
* @param key A key string.
* @return true if the key exists in the JSONObject.
*/
public boolean has(String key) {
return this.map.containsKey(key);
}
/**
* Increment a property of a JSONObject. If there is no such property, create one with a value of 1
* (Integer). If there is such a property, and if it is an Integer, Long, Double, Float, BigInteger,
* or BigDecimal then add one to it. No overflow bounds checking is performed, so callers should
* initialize the key prior to this call with an appropriate type that can handle the maximum
* expected value.
*
* @param key A key string.
* @return this.
* @throws JSONException If there is already a property with this name that is not an Integer, Long,
* Double, or Float.
*/
public JSONObject increment(String key) throws JSONException {
Object value = this.opt(key);
switch (value) {
case
null -> this.put(key, 1);
case
Integer i -> this.put(key, i + 1);
case
Long l -> this.put(key, l + 1L);
case
BigInteger bigInteger -> this.put(key, bigInteger.add(BigInteger.ONE));
case
Float v -> this.put(key, v + 1.0f);
case
Double v -> this.put(key, v + 1.0d);
case
BigDecimal bigDecimal -> this.put(key, bigDecimal.add(BigDecimal.ONE));
default ->
throw new JSONException("Unable to increment [" + JSONUtils.quote(key) + "].");
}
return this;
}
/**
* Determine if the value associated with the key is null or if there is no
* value.
*
* @param key A key string.
* @return true if there is no value associated with the key or if the value is the Null.TYPE
* object.
*/
public boolean isNull(String key) {
return Null.TYPE.equals(this.opt(key));
}
/**
* Get an enumeration of the keys of the JSONObject. Modifying this key Set will also modify the
* JSONObject. Use with caution.
*
* @see Set#iterator()
*
* @return An iterator of the keys.
*/
public Iterator keys() {
return this.keySet().iterator();
}
/**
* Get a set of keys of the JSONObject. Modifying this key Set will also modify the JSONObject. Use
* with caution.
*
* @see Map#keySet()
*
* @return A keySet.
*/
public Set keySet() {
return this.map.keySet();
}
/**
* Get a set of entries of the JSONObject. These are raw values and may not match what is returned
* by the JSONObject get* and opt* functions. Modifying the returned EntrySet or the Entry objects
* contained therein will modify the backing JSONObject. This does not return a clone or a read-only
* view. Use with caution.
*
* @see Map#entrySet()
*
* @return An Entry Set
*/
protected Set> entrySet() {
return this.map.entrySet();
}
/**
* Get the number of keys stored in the JSONObject.
*
* @return The number of keys in the JSONObject.
*/
public int length() {
return this.map.size();
}
/**
* Removes all of the elements from this JSONObject. The JSONObject will be empty after this call
* returns.
*/
public void clear() {
this.map.clear();
}
/**
* Check if JSONObject is empty.
*
* @return true if JSONObject is empty, otherwise false.
*/
public boolean isEmpty() {
return this.map.isEmpty();
}
/**
* Produce a JSONArray containing the names of the elements of this JSONObject.
*
* @return A JSONArray containing the key strings, or null if the JSONObject is empty.
*/
public JSONArray names() {
if(this.map.isEmpty()) {
return null;
}
return new JSONArray(this.map.keySet());
}
/**
* Get an optional value associated with a key.
*
* @param key A key string.
* @return An object which is the value, or null if there is no value.
*/
public Object opt(String key) {
return key == null ? null : this.map.get(key);
}
/**
* Get the enum value associated with a key.
*
* @param Enum Type
* @param clazz The type of enum to retrieve.
* @param key A key string.
* @return The enum value associated with the key or null if not found
*/
public > E optEnum(Class clazz, String key) {
return this.optEnum(clazz, key, null);
}
/**
* Get the enum value associated with a key.
*
* @param Enum Type
* @param clazz The type of enum to retrieve.
* @param key A key string.
* @param defaultValue The default in case the value is not found
* @return The enum value associated with the key or defaultValue if the value is not found or
* cannot be assigned to clazz
*/
public > E optEnum(Class clazz, String key, E defaultValue) {
try {
Object val = this.opt(key);
if (Null.TYPE.equals(val)) {
return defaultValue;
}
if (clazz.isAssignableFrom(val.getClass())) {
// we just checked it!
@SuppressWarnings("unchecked")
E myE = (E) val;
return myE;
}
return Enum.valueOf(clazz, val.toString());
}
catch (
IllegalArgumentException | NullPointerException e) {
return defaultValue;
}
}
/**
* Get an optional boolean associated with a key. It returns false if there is no such key, or if
* the value is not Boolean.TRUE or the String "true".
*
* @param key A key string.
* @return The truth.
*/
public boolean optBoolean(String key) {
return this.optBoolean(key, false);
}
/**
* Get an optional boolean associated with a key. It returns the defaultValue if there is no such
* key, or if it is not a Boolean or the String "true" or "false" (case-insensitive).
*
* @param key A key string.
* @param defaultValue The default.
* @return The truth.
*/
public boolean optBoolean(String key, boolean defaultValue) {
Object val = this.opt(key);
if (Null.TYPE.equals(val)) {
return defaultValue;
}
if (val instanceof Boolean){
return (Boolean) val;
}
try {
// we'll use the get anyway because it does string conversion.
return this.getBoolean(key);
}
catch (Exception e) {
return defaultValue;
}
}
/**
* Get an optional boolean object associated with a key. It returns false if there is no such key,
* or if the value is not Boolean.TRUE or the String "true".
*
* @param key A key string.
* @return The truth.
*/
public Boolean optBooleanObject(String key) {
return this.optBooleanObject(key, false);
}
/**
* Get an optional boolean object associated with a key. It returns the defaultValue if there is no
* such key, or if it is not a Boolean or the String "true" or "false" (case-insensitive).
*
* @param key A key string.
* @param defaultValue The default.
* @return The truth.
*/
public Boolean optBooleanObject(String key, Boolean defaultValue) {
Object val = this.opt(key);
if (Null.TYPE.equals(val)) {
return defaultValue;
}
if (val instanceof Boolean){
return (Boolean) val;
}
try {
// we'll use the get anyway because it does string conversion.
return this.getBoolean(key);
}
catch (Exception e) {
return defaultValue;
}
}
/**
* Get an optional BigDecimal associated with a key, or the defaultValue if there is no such key or
* if its value is not a number. If the value is a string, an attempt will be made to evaluate it as
* a number. If the value is float or double, then the {@link BigDecimal#BigDecimal(double)}
* constructor will be used. See notes on the constructor for conversion issues that may arise.
*
* @param key A key string.
* @param defaultValue The default.
* @return An object which is the value.
*/
public BigDecimal optBigDecimal(String key, BigDecimal defaultValue) {
Object val = this.opt(key);
return JSONUtils.objectToBigDecimal(val, defaultValue);
}
/**
* Get an optional BigInteger associated with a key, or the defaultValue if there is no such key or
* if its value is not a number. If the value is a string, an attempt will be made to evaluate it as
* a number.
*
* @param key A key string.
* @param defaultValue The default.
* @return An object which is the value.
*/
public BigInteger optBigInteger(String key, BigInteger defaultValue) {
return this.optBigInteger(key, defaultValue, new JSONParserConfiguration());
}
/**
* Get an optional BigInteger associated with a key, or the defaultValue if there is no such key or
* if its value is not a number. If the value is a string, an attempt will be made to evaluate it as
* a number.
*
* @param key A key string.
* @param defaultValue The default.
* @param pconfig A configuration whose {@code maxNumberLength} bounds the number of decimal digits
* in the returned integer. Values exceeding this length are treated as unconvertible and
* {@code defaultValue} is returned. Pass a configuration with
* {@link ParserConfiguration#UNDEFINED_MAXIMUM_NUMBER_LENGTH} to disable this check.
* @return An object which is the value.
*/
public BigInteger optBigInteger(String key, BigInteger defaultValue,
JSONParserConfiguration pconfig) {
Object val = this.opt(key);
return JSONUtils.objectToBigInteger(val, defaultValue, pconfig);
}
/**
* Get an optional double associated with a key, or NaN if there is no such key or if its value is
* not a number. If the value is a string, an attempt will be made to evaluate it as a number.
*
* @param key A string which is the key.
* @return An object which is the value.
*/
public double optDouble(String key) {
return this.optDouble(key, Double.NaN);
}
/**
* Get an optional double associated with a key, or the defaultValue if there is no such key or if
* its value is not a number. If the value is a string, an attempt will be made to evaluate it as a
* number.
*
* @param key A key string.
* @param defaultValue The default.
* @return An object which is the value.
*/
public double optDouble(String key, double defaultValue) {
Number val = this.optNumber(key);
if (val == null) {
return defaultValue;
}
return val.doubleValue();
}
/**
* Get an optional Double object associated with a key, or NaN if there is no such key or if its
* value is not a number. If the value is a string, an attempt will be made to evaluate it as a
* number.
*
* @param key A string which is the key.
* @return An object which is the value.
*/
public Double optDoubleObject(String key) {
return this.optDoubleObject(key, Double.NaN);
}
/**
* Get an optional Double object associated with a key, or the defaultValue if there is no such key
* or if its value is not a number. If the value is a string, an attempt will be made to evaluate it
* as a number.
*
* @param key A key string.
* @param defaultValue The default.
* @return An object which is the value.
*/
public Double optDoubleObject(String key, Double defaultValue) {
Number val = this.optNumber(key);
if (val == null) {
return defaultValue;
}
return val.doubleValue();
}
/**
* Get the optional float value associated with an index. NaN is returned if there is no value for
* the index, or if the value is not a number and cannot be converted to a number.
*
* @param key A key string.
* @return The value.
*/
public float optFloat(String key) {
return this.optFloat(key, Float.NaN);
}
/**
* Get the optional float value associated with an index. The defaultValue is returned if there is
* no value for the index, or if the value is not a number and cannot be converted to a number.
*
* @param key A key string.
* @param defaultValue The default value.
* @return The value.
*/
public float optFloat(String key, float defaultValue) {
Number val = this.optNumber(key);
if (val == null) {
return defaultValue;
}
return val.floatValue();
}
/**
* Get the optional Float object associated with an index. NaN is returned if there is no value for
* the index, or if the value is not a number and cannot be converted to a number.
*
* @param key A key string.
* @return The object.
*/
public Float optFloatObject(String key) {
return this.optFloatObject(key, Float.NaN);
}
/**
* Get the optional Float object associated with an index. The defaultValue is returned if there is
* no value for the index, or if the value is not a number and cannot be converted to a number.
*
* @param key A key string.
* @param defaultValue The default object.
* @return The object.
*/
public Float optFloatObject(String key, Float defaultValue) {
Number val = this.optNumber(key);
if (val == null) {
return defaultValue;
}
return val.floatValue();
}
/**
* Get an optional int value associated with a key, or zero if there is no such key or if the value
* is not a number. If the value is a string, an attempt will be made to evaluate it as a number.
*
* @param key A key string.
* @return An object which is the value.
*/
public int optInt(String key) {
return this.optInt(key, 0);
}
/**
* Get an optional int value associated with a key, or the default if there is no such key or if the
* value is not a number. If the value is a string, an attempt will be made to evaluate it as a
* number.
*
* @param key A key string.
* @param defaultValue The default.
* @return An object which is the value.
*/
public int optInt(String key, int defaultValue) {
final Number val = this.optNumber(key, null);
if (val == null) {
return defaultValue;
}
return val.intValue();
}
/**
* Get an optional Integer object associated with a key, or zero if there is no such key or if the
* value is not a number. If the value is a string, an attempt will be made to evaluate it as a
* number.
*
* @param key A key string.
* @return An object which is the value.
*/
public Integer optIntegerObject(String key) {
return this.optIntegerObject(key, 0);
}
/**
* Get an optional Integer object associated with a key, or the default if there is no such key or
* if the value is not a number. If the value is a string, an attempt will be made to evaluate it as
* a number.
*
* @param key A key string.
* @param defaultValue The default.
* @return An object which is the value.
*/
public Integer optIntegerObject(String key, Integer defaultValue) {
final Number val = this.optNumber(key, null);
if (val == null) {
return defaultValue;
}
return val.intValue();
}
/**
* Get an optional JSONArray associated with a key. It returns null if there is no such key, or if
* its value is not a JSONArray.
*
* @param key A key string.
* @return A JSONArray which is the value.
*/
public JSONArray optJSONArray(String key) {
return this.optJSONArray(key, null);
}
/**
* Get an optional JSONArray associated with a key, or the default if there is no such key, or if
* its value is not a JSONArray.
*
* @param key A key string.
* @param defaultValue The default.
* @return A JSONArray which is the value.
*/
public JSONArray optJSONArray(String key, JSONArray defaultValue) {
Object object = this.opt(key);
return object instanceof JSONArray ? (JSONArray) object : defaultValue;
}
/**
* Get an optional JSONObject associated with a key. It returns null if there is no such key, or if
* its value is not a JSONObject.
*
* @param key A key string.
* @return A JSONObject which is the value.
*/
public JSONObject optJSONObject(String key) { return this.optJSONObject(key, null); }
/**
* Get an optional JSONObject associated with a key, or the default if there is no such key or if
* the value is not a JSONObject.
*
* @param key A key string.
* @param defaultValue The default.
* @return An JSONObject which is the value.
*/
public JSONObject optJSONObject(String key, JSONObject defaultValue) {
Object object = this.opt(key);
return object instanceof JSONObject ? (JSONObject) object : defaultValue;
}
/**
* Get an optional long value associated with a key, or zero if there is no such key or if the value
* is not a number. If the value is a string, an attempt will be made to evaluate it as a number.
*
* @param key A key string.
* @return An object which is the value.
*/
public long optLong(String key) {
return this.optLong(key, 0);
}
/**
* Get an optional long value associated with a key, or the default if there is no such key or if
* the value is not a number. If the value is a string, an attempt will be made to evaluate it as a
* number.
*
* @param key A key string.
* @param defaultValue The default.
* @return An object which is the value.
*/
public long optLong(String key, long defaultValue) {
final Number val = this.optNumber(key, null);
if (val == null) {
return defaultValue;
}
return val.longValue();
}
/**
* Get an optional Long object associated with a key, or zero if there is no such key or if the
* value is not a number. If the value is a string, an attempt will be made to evaluate it as a
* number.
*
* @param key A key string.
* @return An object which is the value.
*/
public Long optLongObject(String key) {
return this.optLongObject(key, 0L);
}
/**
* Get an optional Long object associated with a key, or the default if there is no such key or if
* the value is not a number. If the value is a string, an attempt will be made to evaluate it as a
* number.
*
* @param key A key string.
* @param defaultValue The default.
* @return An object which is the value.
*/
public Long optLongObject(String key, Long defaultValue) {
final Number val = this.optNumber(key, null);
if (val == null) {
return defaultValue;
}
return val.longValue();
}
/**
* Get an optional {@link Number} value associated with a key, or null if there is no
* such key or if the value is not a number. If the value is a string, an attempt will be made to
* evaluate it as a number ({@link BigDecimal}). This method would be used in cases where type
* coercion of the number value is unwanted.
*
* @param key A key string.
* @return An object which is the value.
*/
public Number optNumber(String key) {
return this.optNumber(key, null);
}
/**
* Get an optional {@link Number} value associated with a key, or the default if there is no such
* key or if the value is not a number. If the value is a string, an attempt will be made to
* evaluate it as a number. This method would be used in cases where type coercion of the number
* value is unwanted.
*
* @param key A key string.
* @param defaultValue The default.
* @return An object which is the value.
*/
public Number optNumber(String key, Number defaultValue) {
Object val = this.opt(key);
if (Null.TYPE.equals(val)) {
return defaultValue;
}
if (val instanceof Number){
return (Number) val;
}
try {
return JSONUtils.stringToNumber(val.toString());
}
catch (Exception e) {
return defaultValue;
}
}
/**
* Get an optional string associated with a key. It returns an empty string if there is no such key.
* If the value is not a string and is not null, then it is converted to a string.
*
* @param key A key string.
* @return A string which is the value.
*/
public String optString(String key) {
return this.optString(key, "");
}
/**
* Get an optional string associated with a key. It returns the defaultValue if there is no such
* key.
*
* @param key A key string.
* @param defaultValue The default.
* @return A string which is the value.
*/
public String optString(String key, String defaultValue) {
Object object = this.opt(key);
return Null.TYPE.equals(object) ? defaultValue : object.toString();
}
/**
* Put a key/boolean pair in the JSONObject.
*
* @param key A key string.
* @param value A boolean which is the value.
* @return this.
* @throws JSONException If the value is non-finite number.
* @throws NullPointerException If the key is null.
*/
public JSONObject put(String key, boolean value) throws JSONException {
return this.put(key, value ? Boolean.TRUE : Boolean.FALSE);
}
/**
* Put a key/value pair in the JSONObject, where the value will be a JSONArray which is produced
* from a Collection.
*
* @param key A key string.
* @param value A Collection value.
* @return this.
* @throws JSONException If the value is non-finite number.
* @throws NullPointerException If the key is null.
*/
public JSONObject put(String key, Collection> value) throws JSONException {
return this.put(key, new JSONArray(value));
}
/**
* Put a key/double pair in the JSONObject.
*
* @param key A key string.
* @param value A double which is the value.
* @return this.
* @throws JSONException If the value is non-finite number.
* @throws NullPointerException If the key is null.
*/
public JSONObject put(String key, double value) throws JSONException {
return this.put(key, Double.valueOf(value));
}
/**
* Put a key/float pair in the JSONObject.
*
* @param key A key string.
* @param value A float which is the value.
* @return this.
* @throws JSONException If the value is non-finite number.
* @throws NullPointerException If the key is null.
*/
public JSONObject put(String key, float value) throws JSONException {
return this.put(key, Float.valueOf(value));
}
/**
* Put a key/int pair in the JSONObject.
*
* @param key A key string.
* @param value An int which is the value.
* @return this.
* @throws JSONException If the value is non-finite number.
* @throws NullPointerException If the key is null.
*/
public JSONObject put(String key, int value) throws JSONException {
return this.put(key, Integer.valueOf(value));
}
/**
* Put a key/long pair in the JSONObject.
*
* @param key A key string.
* @param value A long which is the value.
* @return this.
* @throws JSONException If the value is non-finite number.
* @throws NullPointerException If the key is null.
*/
public JSONObject put(String key, long value) throws JSONException {
return this.put(key, Long.valueOf(value));
}
/**
* Put a key/value pair in the JSONObject, where the value will be a JSONObject which is produced
* from a Map.
*
* @param key A key string.
* @param value A Map value.
* @return this.
* @throws JSONException If the value is non-finite number.
* @throws NullPointerException If the key is null.
*/
public JSONObject put(String key, Map, ?> value) throws JSONException {
return this.put(key, new JSONObject(value));
}
/**
* Put a key/value pair in the JSONObject. If the value is null, then the key will be
* removed from the JSONObject if it is present.
*
* @param key A key string.
* @param value types: Boolean, Double, Integer, JSONArray, JSONObject, Long, String, or the
* JSONObject.NULL object.
* @return this.
* @throws JSONException If the value is non-finite number.
* @throws NullPointerException If the key is null.
*/
public JSONObject put(String key, Object value) throws JSONException {
if (key == null) {
throw new NullPointerException("Null key.");
}
if (value != null) {
JSONUtils.testValidity(value);
this.map.put(key, value);
}
else {
this.remove(key);
}
return this;
}
/**
* Put a key/value pair in the JSONObject, but only if the key and the value are both non-null, and
* only if there is not already a member with that name.
*
* @param key key to insert into
* @param value value to insert
* @return this.
* @throws JSONException if the key is a duplicate
*/
public JSONObject putOnce(String key, Object value) throws JSONException {
if (key != null && value != null) {
if (this.opt(key) != null) {
throw new JSONException("Duplicate key \"" + key + "\"");
}
return this.put(key, value);
}
return this;
}
/**
* Put a key/value pair in the JSONObject, but only if the key and the value are both non-null.
*
* @param key A key string.
* @param value An object which is the value. It should be of one of these types: Boolean, Double,
* Integer, JSONArray, JSONObject, Long, String, or the JSONObject.NULL object.
* @return this.
* @throws JSONException If the value is a non-finite number.
*/
public JSONObject putOpt(String key, Object value) throws JSONException {
if (key != null && value != null) {
return this.put(key, value);
}
return this;
}
/**
* Creates a JSONPointer using an initialization string and tries to match it to an item within this
* JSONObject. For example, given a JSONObject initialized with this document:
*
* {
* "a":{"b":"c"}
* }
*
* and this JSONPointer string:
*
* "/a/b"
*
* Then this method will return the String "c". A JSONPointerException may be thrown from code
* called by this method.
*
* @param jsonPointer string that can be used to create a JSONPointer
* @return the item matched by the JSONPointer, otherwise null
*/
public Object query(String jsonPointer) {
return query(new JSONPointer(jsonPointer));
}
/**
* Uses a user initialized JSONPointer and tries to match it to an item within this JSONObject. For
* example, given a JSONObject initialized with this document:
*
* {
* "a":{"b":"c"}
* }
*
* and this JSONPointer:
*
* "/a/b"
*
* Then this method will return the String "c". A JSONPointerException may be thrown from code
* called by this method.
*
* @param jsonPointer string that can be used to create a JSONPointer
* @return the item matched by the JSONPointer, otherwise null
*/
public Object query(JSONPointer jsonPointer) {
return jsonPointer.queryFrom(this);
}
/**
* Queries and returns a value from this object using {@code jsonPointer}, or returns null if the
* query fails due to a missing key.
*
* @param jsonPointer the string representation of the JSON pointer
* @return the queried value or {@code null}
* @throws IllegalArgumentException if {@code jsonPointer} has invalid syntax
*/
public Object optQuery(String jsonPointer) {
return optQuery(new JSONPointer(jsonPointer));
}
/**
* Queries and returns a value from this object using {@code jsonPointer}, or returns null if the
* query fails due to a missing key.
*
* @param jsonPointer The JSON pointer
* @return the queried value or {@code null}
* @throws IllegalArgumentException if {@code jsonPointer} has invalid syntax
*/
public Object optQuery(JSONPointer jsonPointer) {
try {
return jsonPointer.queryFrom(this);
}
catch (JSONPointerException e) {
return null;
}
}
/**
* Remove a name and its value, if present.
*
* @param key The name to be removed.
* @return The value that was associated with the name, or null if there was no value.
*/
public Object remove(String key) {
return this.map.remove(key);
}
/**
* Determine if two JSONObjects are similar. They must contain the same set of names which must be
* associated with similar values.
*
* @param other The other JSONObject
* @return true if they are equal
*/
public boolean similar(Object other) {
try {
if (!(other instanceof JSONObject)) {
return false;
}
if (!this.keySet().equals(((JSONObject)other).keySet())) {
return false;
}
return checkSimilarEntries(other);
}
catch (Exception e) {
return false;
}
}
private boolean checkSimilarEntries(Object other) {
for (final Entry entry : this.entrySet()) {
String name = entry.getKey();
Object valueThis = entry.getValue();
Object valueOther = ((JSONObject)other).get(name);
if(valueThis == valueOther) {
continue;
}
if(valueThis == null) {
return false;
}
if (!checkObjectType(valueThis, valueOther)) {
return false;
}
}
return true;
}
/**
* Convenience function. Compares types of two objects.
*
* @param valueThis Object whose type is being checked
* @param valueOther Reference object
* @return true if match, else false
*/
private boolean checkObjectType(Object valueThis, Object valueOther) {
if (valueThis instanceof JSONObject) {
return ((JSONObject)valueThis).similar(valueOther);
}
else if (valueThis instanceof JSONArray) {
return ((JSONArray)valueThis).similar(valueOther);
}
else if (valueThis instanceof Number && valueOther instanceof Number) {
return JSONUtils.isNumberSimilar((Number)valueThis, (Number)valueOther);
}
else if (valueThis instanceof JSONString && valueOther instanceof JSONString) {
return ((JSONString) valueThis).toJSONString().equals(((JSONString) valueOther).toJSONString());
}
else if (!valueThis.equals(valueOther)) {
return false;
}
return true;
}
/**
* Produce a JSONArray containing the values of the members of this JSONObject.
*
* @param names A JSONArray containing a list of key strings. This determines the sequence of the
* values in the result.
* @return A JSONArray of values.
* @throws JSONException If any of the values are non-finite numbers.
*/
public JSONArray toJSONArray(JSONArray names) throws JSONException {
if (names == null || names.isEmpty()) {
return null;
}
JSONArray ja = new JSONArray();
for (int i = 0; i < names.length(); i += 1) {
ja.put(this.opt(names.getString(i)));
}
return ja;
}
/**
* Make a JSON text of this JSONObject. For compactness, no whitespace is added. If this would not
* result in a syntactically correct JSON text, then null will be returned instead.
*
* Warning: This method assumes that the data structure is acyclical.
*
*
* @return a printable, displayable, portable, transmittable representation of the object, beginning
* with { (left brace) and ending with }
* (right brace).
*/
@Override
public String toString() {
try {
return this.toString(0);
}
catch (Exception e) {
return null;
}
}
/**
* Make a pretty-printed JSON text of this JSONObject.
*
*
If
{@code indentFactor > 0}
and the {@link JSONObject} has only one key, then the
* object will be output on a single line:
*
{@code {"key": 1}}
*
*
If an object has 2 or more keys, then it will be output across multiple lines:
* Warning: This method assumes that the data structure is acyclical.
*
*
* @param indentFactor The number of spaces to add to each level of indentation.
* @return a printable, displayable, portable, transmittable representation of the object, beginning
* with { (left brace) and ending with }
* (right brace).
* @throws JSONException If the object contains an invalid number.
*/
public String toString(int indentFactor) throws JSONException {
// 6 characters are the minimum to serialise a key value pair e.g.: "k":1,
// and we don't want to oversize the initial capacity
int initialSize = map.size() * 6;
Writer w = new StringBuilderWriter(Math.max(initialSize, 16));
return this.write(w, indentFactor, 0).toString();
}
/**
* Make a JSON text of an Object value. If the object has an
* value.toJSONString() method, then that method will be used to produce the
* JSON text. The method is required to produce a strictly conforming text.
* If the object does not contain a toJSONString method (which is the most
* common case), then a text will be produced by other means. If the value
* is an array or Collection, then a JSONArray will be made from it and its
* toJSONString method will be called. If the value is a MAP, then a
* JSONObject will be made from it and its toJSONString method will be
* called. Otherwise, the value's toString method will be called, and the
* result will be quoted.
*
*
* Warning: This method assumes that the data structure is acyclical.
*
* @param value
* The value to be serialized.
* @return a printable, displayable, transmittable representation of the
* object, beginning with { (left
* brace) and ending with } (right
* brace).
* @throws JSONException
* If the value is or contains an invalid number.
*/
public static String valueToString(Object value) throws JSONException {
// moves the implementation to JSONWriter as:
// 1. It makes more sense to be part of the writer class
// 2. For Android support this method is not available. By implementing it in the Writer
// Android users can use the writer with the built in Android JSONObject implementation.
return JSONWriter.valueToString(value);
}
/**
* Wrap an object, if necessary. If the object is null, return the NULL
* object. If it is an array or collection, wrap it in a JSONArray. If it is
* a map, wrap it in a JSONObject. If it is a standard property (Double,
* String, et al) then it is already wrapped. Otherwise, if it comes from
* one of the java packages, turn it into a string. And if it doesn't, try
* to wrap it in a JSONObject. If the wrapping fails, then null is returned.
*
* @param object
* The object to wrap
* @return The wrapped value
*/
// TODO: Uncomment later
/*
public static Object wrap(Object object) {
return wrap(object, null);
}
*/
/**
* Wrap an object, if necessary. If the object is null, return the NULL
* object. If it is an array or collection, wrap it in a JSONArray. If it is
* a map, wrap it in a JSONObject. If it is a standard property (Double,
* String, et al) then it is already wrapped. Otherwise, if it comes from
* one of the java packages, turn it into a string. And if it doesn't, try
* to wrap it in a JSONObject. If the wrapping fails, then null is returned.
*
* @param object
* The object to wrap
* @param recursionDepth
* Variable for tracking the count of nested object creations.
* @param jsonParserConfiguration
* Variable to pass parser custom configuration for json parsing.
* @return The wrapped value
*/
// TODO: Uncomment later
/*
static Object wrap(Object object, int recursionDepth, JSONParserConfiguration jsonParserConfiguration) {
return wrap(object, null, recursionDepth, jsonParserConfiguration);
}
private static Object wrap(Object object, Set