diff --git a/src/main/java/org/json/JSONObject.java b/src/main/java/org/json/JSONObject.java index bf9f920..bcd218e 100644 --- a/src/main/java/org/json/JSONObject.java +++ b/src/main/java/org/json/JSONObject.java @@ -1484,6 +1484,18 @@ public class JSONObject { || val instanceof Short || val instanceof Byte){ return BigInteger.valueOf(((Number) val).longValue()); } + return attemptConversionToBigInteger(val, defaultValue, maxNumberLength); + } + + /** + * Convenience method to attempt conversion of value to BigInteger. + * Added to reduce complexity of objectToBigInteger() + * @param val the value to be converted + * @param defaultValue the default value to use if conversion is not attempted or fails + * @param maxNumberLength the max length allowed for BigIntegers + * @return the converted value, or the defaultValue + */ + private static BigInteger attemptConversionToBigInteger(Object val, BigInteger defaultValue, int maxNumberLength) { // don't check if it's a string in case of unchecked Number subclasses try { /** @@ -2799,7 +2811,7 @@ public class JSONObject { jsonParserConfiguration = new JSONParserConfiguration(); } // user declines max number checking - if (jsonParserConfiguration.getMaxNumberLength() == JSONParserConfiguration.UNDEFINED_MAXIMUM_NUMBER_LENGTH) { + if (jsonParserConfiguration.getMaxNumberLength() == ParserConfiguration.UNDEFINED_MAXIMUM_NUMBER_LENGTH) { return stringToNumber(string); } if (string.length() <= jsonParserConfiguration.getMaxNumberLength()) { diff --git a/src/main/java/org/json/ParserConfiguration.java b/src/main/java/org/json/ParserConfiguration.java index df700b3..e80093c 100644 --- a/src/main/java/org/json/ParserConfiguration.java +++ b/src/main/java/org/json/ParserConfiguration.java @@ -58,8 +58,9 @@ public class ParserConfiguration { * * @param keepStrings A boolean indicating whether to preserve strings during parsing. * @param maxNestingDepth An integer representing the maximum allowed nesting depth. - * @deprecated + * @deprecated Use the with*() methods instead */ + @Deprecated protected ParserConfiguration(final boolean keepStrings, final int maxNestingDepth) { this.keepStrings = keepStrings; this.maxNestingDepth = maxNestingDepth; diff --git a/src/main/java/org/json/XML.java b/src/main/java/org/json/XML.java index 195da8d..3247587 100644 --- a/src/main/java/org/json/XML.java +++ b/src/main/java/org/json/XML.java @@ -667,7 +667,7 @@ public class XML { if ((initial >= '0' && initial <= '9') || initial == '-') { try { // user declines max number checking - if (xmlParserConfiguration.getMaxNumberLength() == JSONParserConfiguration.UNDEFINED_MAXIMUM_NUMBER_LENGTH) { + if (xmlParserConfiguration.getMaxNumberLength() == ParserConfiguration.UNDEFINED_MAXIMUM_NUMBER_LENGTH) { return stringToNumber(string); } if(string.length() <= xmlParserConfiguration.getMaxNumberLength()) {