diff --git a/src/main/java/org/codehaus/jettison/json/JSONObject.java b/src/main/java/org/codehaus/jettison/json/JSONObject.java index 5932cc9..5c9ff4d 100644 --- a/src/main/java/org/codehaus/jettison/json/JSONObject.java +++ b/src/main/java/org/codehaus/jettison/json/JSONObject.java @@ -1346,6 +1346,16 @@ static String valueToString(Object value, int indentFactor, int indent, boolean * value is 500 * @param newRecursionDepthLimit the new recursion depth limit to set */ + public static void setGlobalRecursionDepthLimit(int newRecursionDepthLimit) { + RECURSION_DEPTH_LIMIT = newRecursionDepthLimit; + } + + /** + * Set the new recursion depth limit to prevent stack overflow issues on deeply nested structures. The default + * value is 500 + * @param newRecursionDepthLimit the new recursion depth limit to set + */ + @Deprecated public void setRecursionDepthLimit(int newRecursionDepthLimit) { RECURSION_DEPTH_LIMIT = newRecursionDepthLimit; } @@ -1355,6 +1365,16 @@ public void setRecursionDepthLimit(int newRecursionDepthLimit) { * value is 500 * @return the recursion depth limit */ + public static int getGlobalRecursionDepthLimit() { + return RECURSION_DEPTH_LIMIT; + } + + /** + * Get the new recursion depth limit to prevent stack overflow issues on deeply nested structures. The default + * value is 500 + * @return the recursion depth limit + */ + @Deprecated public int getRecursionDepthLimit() { return RECURSION_DEPTH_LIMIT; } diff --git a/src/test/java/org/codehaus/jettison/json/JSONArrayTest.java b/src/test/java/org/codehaus/jettison/json/JSONArrayTest.java index 8aeb9df..88333f3 100644 --- a/src/test/java/org/codehaus/jettison/json/JSONArrayTest.java +++ b/src/test/java/org/codehaus/jettison/json/JSONArrayTest.java @@ -65,7 +65,7 @@ public void testInfiniteLoop2() { } public void testIssue52() throws JSONException { - new JSONObject().setRecursionDepthLimit(10); + JSONObject.setGlobalRecursionDepthLimit(10); new JSONArray("[{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {a:10}]"); }