@@ -149,18 +149,22 @@ public JSONArray(String source) throws JSONException {
149149 * A Collection.
150150 */
151151 public JSONArray (Collection <?> collection ) {
152- this (collection , 0 );
152+ this (collection , 0 , new JSONParserConfiguration () );
153153 }
154154
155- protected JSONArray (Collection <?> collection , int recursionDepth ) {
156- if (recursionDepth > JSONObject .RECURSION_DEPTH_LIMIT ) {
157- throw new JSONException ("JSONArray has reached recursion depth limit of " + JSONObject .RECURSION_DEPTH_LIMIT );
155+ public JSONArray (Collection <?> collection , JSONParserConfiguration jsonParserConfiguration ) {
156+ this (collection , 0 , jsonParserConfiguration );
157+ }
158+
159+ protected JSONArray (Collection <?> collection , int recursionDepth , JSONParserConfiguration jsonParserConfiguration ) {
160+ if (recursionDepth > jsonParserConfiguration .getMaxNestingDepth ()) {
161+ throw new JSONException ("JSONArray has reached recursion depth limit of " + jsonParserConfiguration .getMaxNestingDepth ());
158162 }
159163 if (collection == null ) {
160164 this .myArrayList = new ArrayList <Object >();
161165 } else {
162166 this .myArrayList = new ArrayList <Object >(collection .size ());
163- this .addAll (collection , true , recursionDepth );
167+ this .addAll (collection , true , recursionDepth , jsonParserConfiguration );
164168 }
165169 }
166170
@@ -1345,7 +1349,27 @@ public JSONArray put(int index, long value) throws JSONException {
13451349 * If a key in the map is <code>null</code>
13461350 */
13471351 public JSONArray put (int index , Map <?, ?> value ) throws JSONException {
1348- this .put (index , new JSONObject (value ));
1352+ this .put (index , new JSONObject (value , new JSONParserConfiguration ()));
1353+ return this ;
1354+ }
1355+
1356+ /**
1357+ * Put a value in the JSONArray, where the value will be a JSONObject that
1358+ * is produced from a Map.
1359+ *
1360+ * @param index
1361+ * The subscript
1362+ * @param value
1363+ * The Map value.
1364+ * @param jsonParserConfiguration
1365+ * Configuration for recursive depth
1366+ * @return
1367+ * @throws JSONException
1368+ * If the index is negative or if the value is an invalid
1369+ * number.
1370+ */
1371+ public JSONArray put (int index , Map <?, ?> value , JSONParserConfiguration jsonParserConfiguration ) throws JSONException {
1372+ this .put (index , new JSONObject (value , jsonParserConfiguration ));
13491373 return this ;
13501374 }
13511375
@@ -1790,11 +1814,11 @@ public boolean isEmpty() {
17901814 * variable to keep the count of how nested the object creation is happening.
17911815 *
17921816 */
1793- private void addAll (Collection <?> collection , boolean wrap , int recursionDepth ) {
1817+ private void addAll (Collection <?> collection , boolean wrap , int recursionDepth , JSONParserConfiguration jsonParserConfiguration ) {
17941818 this .myArrayList .ensureCapacity (this .myArrayList .size () + collection .size ());
17951819 if (wrap ) {
17961820 for (Object o : collection ){
1797- this .put (JSONObject .wrap (o , recursionDepth + 1 ));
1821+ this .put (JSONObject .wrap (o , recursionDepth + 1 , jsonParserConfiguration ));
17981822 }
17991823 } else {
18001824 for (Object o : collection ){
@@ -1823,7 +1847,14 @@ private void addAll(Iterable<?> iter, boolean wrap) {
18231847 }
18241848 }
18251849 }
1826-
1850+
1851+ /**
1852+ * Add an array's elements to the JSONArray.
1853+ *
1854+ * @param array
1855+ * @param wrap
1856+ * @throws JSONException
1857+ */
18271858 private void addAll (Object array , boolean wrap ) throws JSONException {
18281859 this .addAll (array , wrap , 0 );
18291860 }
@@ -1836,23 +1867,37 @@ private void addAll(Object array, boolean wrap) throws JSONException {
18361867 * JSONArray, Collection, or Iterable, an exception will be
18371868 * thrown.
18381869 * @param wrap
1870+ * @param recursionDepth
1871+ */
1872+ private void addAll (Object array , boolean wrap , int recursionDepth ) {
1873+ addAll (array , wrap , recursionDepth , new JSONParserConfiguration ());
1874+ }
1875+ /**
1876+ * Add an array's elements to the JSONArray.
1877+ *`
1878+ * @param array
1879+ * Array. If the parameter passed is null, or not an array,
1880+ * JSONArray, Collection, or Iterable, an exception will be
1881+ * thrown.
1882+ * @param wrap
18391883 * {@code true} to call {@link JSONObject#wrap(Object)} for each item,
18401884 * {@code false} to add the items directly
18411885 * @param recursionDepth
18421886 * Variable to keep the count of how nested the object creation is happening.
1843- *
1887+ * @param recursionDepth
1888+ * Variable to pass parser custom configuration for json parsing.
18441889 * @throws JSONException
18451890 * If not an array or if an array value is non-finite number.
18461891 * @throws NullPointerException
18471892 * Thrown if the array parameter is null.
18481893 */
1849- private void addAll (Object array , boolean wrap , int recursionDepth ) throws JSONException {
1894+ private void addAll (Object array , boolean wrap , int recursionDepth , JSONParserConfiguration jsonParserConfiguration ) throws JSONException {
18501895 if (array .getClass ().isArray ()) {
18511896 int length = Array .getLength (array );
18521897 this .myArrayList .ensureCapacity (this .myArrayList .size () + length );
18531898 if (wrap ) {
18541899 for (int i = 0 ; i < length ; i += 1 ) {
1855- this .put (JSONObject .wrap (Array .get (array , i ), recursionDepth + 1 ));
1900+ this .put (JSONObject .wrap (Array .get (array , i ), recursionDepth + 1 , jsonParserConfiguration ));
18561901 }
18571902 } else {
18581903 for (int i = 0 ; i < length ; i += 1 ) {
0 commit comments