@@ -149,18 +149,22 @@ public JSONArray(String source) throws JSONException {
149
149
* A Collection.
150
150
*/
151
151
public JSONArray (Collection <?> collection ) {
152
- this (collection , 0 );
152
+ this (collection , 0 , new JSONParserConfiguration () );
153
153
}
154
154
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 ());
158
162
}
159
163
if (collection == null ) {
160
164
this .myArrayList = new ArrayList <Object >();
161
165
} else {
162
166
this .myArrayList = new ArrayList <Object >(collection .size ());
163
- this .addAll (collection , true , recursionDepth );
167
+ this .addAll (collection , true , recursionDepth , jsonParserConfiguration );
164
168
}
165
169
}
166
170
@@ -1345,7 +1349,27 @@ public JSONArray put(int index, long value) throws JSONException {
1345
1349
* If a key in the map is <code>null</code>
1346
1350
*/
1347
1351
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 ));
1349
1373
return this ;
1350
1374
}
1351
1375
@@ -1790,11 +1814,11 @@ public boolean isEmpty() {
1790
1814
* variable to keep the count of how nested the object creation is happening.
1791
1815
*
1792
1816
*/
1793
- private void addAll (Collection <?> collection , boolean wrap , int recursionDepth ) {
1817
+ private void addAll (Collection <?> collection , boolean wrap , int recursionDepth , JSONParserConfiguration jsonParserConfiguration ) {
1794
1818
this .myArrayList .ensureCapacity (this .myArrayList .size () + collection .size ());
1795
1819
if (wrap ) {
1796
1820
for (Object o : collection ){
1797
- this .put (JSONObject .wrap (o , recursionDepth + 1 ));
1821
+ this .put (JSONObject .wrap (o , recursionDepth + 1 , jsonParserConfiguration ));
1798
1822
}
1799
1823
} else {
1800
1824
for (Object o : collection ){
@@ -1823,7 +1847,14 @@ private void addAll(Iterable<?> iter, boolean wrap) {
1823
1847
}
1824
1848
}
1825
1849
}
1826
-
1850
+
1851
+ /**
1852
+ * Add an array's elements to the JSONArray.
1853
+ *
1854
+ * @param array
1855
+ * @param wrap
1856
+ * @throws JSONException
1857
+ */
1827
1858
private void addAll (Object array , boolean wrap ) throws JSONException {
1828
1859
this .addAll (array , wrap , 0 );
1829
1860
}
@@ -1836,23 +1867,37 @@ private void addAll(Object array, boolean wrap) throws JSONException {
1836
1867
* JSONArray, Collection, or Iterable, an exception will be
1837
1868
* thrown.
1838
1869
* @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
1839
1883
* {@code true} to call {@link JSONObject#wrap(Object)} for each item,
1840
1884
* {@code false} to add the items directly
1841
1885
* @param recursionDepth
1842
1886
* 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.
1844
1889
* @throws JSONException
1845
1890
* If not an array or if an array value is non-finite number.
1846
1891
* @throws NullPointerException
1847
1892
* Thrown if the array parameter is null.
1848
1893
*/
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 {
1850
1895
if (array .getClass ().isArray ()) {
1851
1896
int length = Array .getLength (array );
1852
1897
this .myArrayList .ensureCapacity (this .myArrayList .size () + length );
1853
1898
if (wrap ) {
1854
1899
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 ));
1856
1901
}
1857
1902
} else {
1858
1903
for (int i = 0 ; i < length ; i += 1 ) {
0 commit comments