diff --git a/src/main/java/org/json/JSONParserConfiguration.java b/src/main/java/org/json/JSONParserConfiguration.java index 910d1cf..1ec1710 100644 --- a/src/main/java/org/json/JSONParserConfiguration.java +++ b/src/main/java/org/json/JSONParserConfiguration.java @@ -5,25 +5,21 @@ package org.json; */ public class JSONParserConfiguration extends ParserConfiguration { - /** - * We can override the default maximum nesting depth if needed. - */ - public static final int DEFAULT_MAXIMUM_NESTING_DEPTH = ParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH; - /** * Configuration with the default values. */ public JSONParserConfiguration() { - this.maxNestingDepth = DEFAULT_MAXIMUM_NESTING_DEPTH; - } - - public JSONParserConfiguration(int maxNestingDepth) { - this.maxNestingDepth = maxNestingDepth; + super(); } @Override protected JSONParserConfiguration clone() { - return new JSONParserConfiguration(DEFAULT_MAXIMUM_NESTING_DEPTH); + return new JSONParserConfiguration(); + } + + @Override + public JSONParserConfiguration withMaxNestingDepth(final int maxNestingDepth) { + return super.withMaxNestingDepth(maxNestingDepth); } } diff --git a/src/test/java/org/json/junit/JSONArrayTest.java b/src/test/java/org/json/junit/JSONArrayTest.java index 349422d..fd01379 100644 --- a/src/test/java/org/json/junit/JSONArrayTest.java +++ b/src/test/java/org/json/junit/JSONArrayTest.java @@ -32,6 +32,7 @@ import org.json.JSONParserConfiguration; import org.json.JSONPointerException; import org.json.JSONString; import org.json.JSONTokener; +import org.json.ParserConfiguration; import org.json.junit.data.MyJsonString; import org.junit.Ignore; import org.junit.Test; @@ -1442,14 +1443,14 @@ public class JSONArrayTest { @Test public void testRecursiveDepthAtPositionDefaultObject() { - HashMap map = JSONObjectTest.buildNestedMap(JSONParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH); + HashMap map = JSONObjectTest.buildNestedMap(ParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH); new JSONArray().put(0, map); } @Test public void testRecursiveDepthAtPosition1000Object() { HashMap map = JSONObjectTest.buildNestedMap(1000); - new JSONArray().put(0, map, new JSONParserConfiguration(1000)); + new JSONArray().put(0, map, new JSONParserConfiguration().withMaxNestingDepth(1000)); } @Test(expected = JSONException.class) @@ -1467,14 +1468,14 @@ public class JSONArrayTest { @Test public void testRecursiveDepthArrayForDefaultLevels() { - ArrayList array = buildNestedArray(JSONParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH); + ArrayList array = buildNestedArray(ParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH); new JSONArray(array, new JSONParserConfiguration()); } @Test public void testRecursiveDepthArrayFor1000Levels() { ArrayList array = buildNestedArray(1000); - JSONParserConfiguration parserConfiguration = new JSONParserConfiguration(1000); + JSONParserConfiguration parserConfiguration = new JSONParserConfiguration().withMaxNestingDepth(1000); new JSONArray(array, parserConfiguration); } diff --git a/src/test/java/org/json/junit/JSONObjectTest.java b/src/test/java/org/json/junit/JSONObjectTest.java index 1a911d8..96f3673 100644 --- a/src/test/java/org/json/junit/JSONObjectTest.java +++ b/src/test/java/org/json/junit/JSONObjectTest.java @@ -35,6 +35,7 @@ import org.json.JSONPointerException; import org.json.JSONParserConfiguration; import org.json.JSONString; import org.json.JSONTokener; +import org.json.ParserConfiguration; import org.json.XML; import org.json.junit.data.BrokenToString; import org.json.junit.data.ExceptionalBean; @@ -3739,7 +3740,7 @@ public class JSONObjectTest { @Test public void issue743SerializationMapWith512Objects() { - HashMap map = buildNestedMap(JSONParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH); + HashMap map = buildNestedMap(ParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH); JSONObject object = new JSONObject(map); String jsonString = object.toString(); } @@ -3747,7 +3748,7 @@ public class JSONObjectTest { @Test public void issue743SerializationMapWith1000Objects() { HashMap map = buildNestedMap(1000); - JSONParserConfiguration parserConfiguration = new JSONParserConfiguration(1000); + JSONParserConfiguration parserConfiguration = new JSONParserConfiguration().withMaxNestingDepth(1000); JSONObject object = new JSONObject(map, parserConfiguration); String jsonString = object.toString(); }