@@ -172,11 +172,6 @@ public String toString() {
172172 */
173173 public static final Object NULL = new Null ();
174174
175- /**
176- * Indicates if BigNumber is to be used
177- */
178- private boolean bigNumberEnabled = false ;
179-
180175 /**
181176 * Parses number token as BigNumber is token length exceeds this value
182177 */
@@ -220,17 +215,14 @@ public JSONObject(JSONObject jo, String[] names) {
220215 *
221216 * @param x
222217 * A JSONTokener object containing the source string.
223- * @param bigNumberEnabled
224- * If numbers should be attempted to be parsed as BigNumbers
225218 * @param bigNumberLength
226219 * Token length when it should be considered as BigNumber
227220 * @throws JSONException
228221 * If there is a syntax error in the source string or a
229222 * duplicated key.
230223 */
231- public JSONObject (JSONTokener x , boolean bigNumberEnabled , int bigNumberLength ) throws JSONException {
224+ public JSONObject (JSONTokener x , int bigNumberLength ) throws JSONException {
232225 this ();
233- this .bigNumberEnabled = bigNumberEnabled ;
234226 this .bigNumberLength = bigNumberLength ;
235227 char c ;
236228 String key ;
@@ -293,31 +285,16 @@ public JSONObject(JSONTokener x, boolean bigNumberEnabled, int bigNumberLength)
293285 /**
294286 * Construct a JSONObject from a JSONTokener.
295287 *
288+ * Using this constructor does not enable BigNumber support.
289+ *
296290 * @param x
297291 * A JSONTokener object containing the source string.
298- * @param bigNumberEnabled
299- * If numbers should be attempted to be parsed as BigNumbers.
300- * If the, the default legnth of token to be considered as BigNumber is 14
301292 * @throws JSONException
302293 * If there is a syntax error in the source string or a
303294 * duplicated key.
304295 */
305- public JSONObject (JSONTokener x , boolean bigNumberEnabled ) throws JSONException {
306- this (x , bigNumberEnabled , 14 );
307- }
308- /**
309- * Construct a JSONObject from a JSONTokener.
310- *
311- * Using this constructor does not enable BigNumber support.
312- *
313- * @param x
314- * A JSONTokener object containing the source string.
315- * @throws JSONException
316- * If there is a syntax error in the source string or a
317- * duplicated key.
318- */
319296 public JSONObject (JSONTokener x ) throws JSONException {
320- this (x , false , 14 );
297+ this (x , 14 );
321298 }
322299
323300 /**
@@ -454,7 +431,7 @@ public JSONObject(Object object, String names[]) {
454431 * duplicated key.
455432 */
456433 public JSONObject (String source , boolean bigNumberEnabled , int bigNumberLength ) throws JSONException {
457- this (new JSONTokener (source ) , bigNumberEnabled , bigNumberLength );
434+ this (new JSONTokener (source , bigNumberEnabled , bigNumberLength ) , bigNumberLength );
458435 }
459436
460437 /**
@@ -472,7 +449,7 @@ public JSONObject(String source, boolean bigNumberEnabled, int bigNumberLength)
472449 * duplicated key.
473450 */
474451 public JSONObject (String source , boolean bigNumberEnabled ) throws JSONException {
475- this (new JSONTokener (source ) , bigNumberEnabled , 14 );
452+ this (new JSONTokener (source , bigNumberEnabled , 14 ) , 14 );
476453 }
477454 /**
478455 * Construct a JSONObject from a source JSON text string. This is the most
@@ -490,7 +467,7 @@ public JSONObject(String source, boolean bigNumberEnabled) throws JSONException
490467 * duplicated key.
491468 */
492469 public JSONObject (String source ) throws JSONException {
493- this (new JSONTokener (source ) , false , 14 );
470+ this (new JSONTokener (source , false , 14 ) , 14 );
494471 }
495472
496473 /**
@@ -573,12 +550,12 @@ public JSONObject accumulate(String key, Object value) throws JSONException {
573550 Object object = this .opt (key );
574551 if (object == null ) {
575552 this .put (key ,
576- value instanceof JSONArray ? new JSONArray ().put (value )
553+ value instanceof JSONArray ? new JSONArray (this . bigNumberLength ).put (value )
577554 : value );
578555 } else if (object instanceof JSONArray ) {
579556 ((JSONArray ) object ).put (value );
580557 } else {
581- this .put (key , new JSONArray ().put (object ).put (value ));
558+ this .put (key , new JSONArray (this . bigNumberLength ).put (object ).put (value ));
582559 }
583560 return this ;
584561 }
@@ -604,7 +581,7 @@ public JSONObject append(String key, Object value) throws JSONException {
604581 testValidity (value );
605582 Object object = this .opt (key );
606583 if (object == null ) {
607- this .put (key , new JSONArray ().put (value ));
584+ this .put (key , new JSONArray (this . bigNumberLength ).put (value ));
608585 } else if (object instanceof JSONArray ) {
609586 this .put (key , ((JSONArray ) object ).put (value ));
610587 } else {
@@ -801,7 +778,7 @@ public Number getNumber(String key) throws JSONException {
801778 if (object instanceof Number ) {
802779 return (Number )object ;
803780 }
804- return stringToNumber (object .toString ());
781+ return stringToNumber (object .toString (), bigNumberLength );
805782 } catch (Exception e ) {
806783 throw new JSONException ("JSONObject[" + quote (key )
807784 + "] is not a number." , e );
@@ -1499,7 +1476,7 @@ public Number optNumber(String key, Number defaultValue) {
14991476 }
15001477
15011478 try {
1502- return stringToNumber (val .toString ());
1479+ return stringToNumber (val .toString (), bigNumberLength );
15031480 } catch (Exception e ) {
15041481 return defaultValue ;
15051482 }
@@ -1682,9 +1659,6 @@ private static <A extends Annotation> A getAnnotation(final Method m, final Clas
16821659 * implementations and interfaces has the annotation. Returns the depth of the
16831660 * annotation in the hierarchy.
16841661 *
1685- * @param <A>
1686- * type of the annotation
1687- *
16881662 * @param m
16891663 * method to check
16901664 * @param annotationClass
@@ -2165,7 +2139,7 @@ protected static boolean isDecimalNotation(final String val) {
21652139 * @throws NumberFormatException thrown if the value is not a valid number. A public
21662140 * caller should catch this and wrap it in a {@link JSONException} if applicable.
21672141 */
2168- protected static Number stringToNumber (final String val ) throws NumberFormatException {
2142+ protected static Number stringToNumber (final String val , int bigNumberLength ) throws NumberFormatException {
21692143 char initial = val .charAt (0 );
21702144 if ((initial >= '0' && initial <= '9' ) || initial == '-' ) {
21712145 // decimal representation
@@ -2231,7 +2205,7 @@ protected static Number stringToNumber(final String val) throws NumberFormatExce
22312205 */
22322206 // Changes to this method must be copied to the corresponding method in
22332207 // the XML class to keep full support for Android
2234- public static Object stringToValue (String string ) {
2208+ public static Object stringToValue (String string , boolean bigNumberEnabled , int bigNumberLength ) {
22352209 if ("" .equals (string )) {
22362210 return string ;
22372211 }
@@ -2256,7 +2230,7 @@ public static Object stringToValue(String string) {
22562230 if ((initial >= '0' && initial <= '9' ) || initial == '-' ) {
22572231 try {
22582232 if (bigNumberEnabled ) {
2259- return stringToNumber (string );
2233+ return stringToNumber (string , bigNumberLength );
22602234 } else {
22612235 if (isDecimalNotation (string )) {
22622236 Double d = Double .valueOf (string );
@@ -2318,7 +2292,7 @@ public JSONArray toJSONArray(JSONArray names) throws JSONException {
23182292 if (names == null || names .isEmpty ()) {
23192293 return null ;
23202294 }
2321- JSONArray ja = new JSONArray ();
2295+ JSONArray ja = new JSONArray (this . bigNumberLength );
23222296 for (int i = 0 ; i < names .length (); i += 1 ) {
23232297 ja .put (this .opt (names .getString (i )));
23242298 }
0 commit comments