mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-03 11:25:30 -04:00
Review comments
This commit is contained in:
parent
abea194120
commit
ffd48afa42
@ -5,25 +5,21 @@ package org.json;
|
|||||||
*/
|
*/
|
||||||
public class JSONParserConfiguration extends ParserConfiguration {
|
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.
|
* Configuration with the default values.
|
||||||
*/
|
*/
|
||||||
public JSONParserConfiguration() {
|
public JSONParserConfiguration() {
|
||||||
this.maxNestingDepth = DEFAULT_MAXIMUM_NESTING_DEPTH;
|
super();
|
||||||
}
|
|
||||||
|
|
||||||
public JSONParserConfiguration(int maxNestingDepth) {
|
|
||||||
this.maxNestingDepth = maxNestingDepth;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JSONParserConfiguration clone() {
|
protected JSONParserConfiguration clone() {
|
||||||
return new JSONParserConfiguration(DEFAULT_MAXIMUM_NESTING_DEPTH);
|
return new JSONParserConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONParserConfiguration withMaxNestingDepth(final int maxNestingDepth) {
|
||||||
|
return super.withMaxNestingDepth(maxNestingDepth);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ import org.json.JSONParserConfiguration;
|
|||||||
import org.json.JSONPointerException;
|
import org.json.JSONPointerException;
|
||||||
import org.json.JSONString;
|
import org.json.JSONString;
|
||||||
import org.json.JSONTokener;
|
import org.json.JSONTokener;
|
||||||
|
import org.json.ParserConfiguration;
|
||||||
import org.json.junit.data.MyJsonString;
|
import org.json.junit.data.MyJsonString;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -1442,14 +1443,14 @@ public class JSONArrayTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRecursiveDepthAtPositionDefaultObject() {
|
public void testRecursiveDepthAtPositionDefaultObject() {
|
||||||
HashMap<String, Object> map = JSONObjectTest.buildNestedMap(JSONParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH);
|
HashMap<String, Object> map = JSONObjectTest.buildNestedMap(ParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH);
|
||||||
new JSONArray().put(0, map);
|
new JSONArray().put(0, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRecursiveDepthAtPosition1000Object() {
|
public void testRecursiveDepthAtPosition1000Object() {
|
||||||
HashMap<String, Object> map = JSONObjectTest.buildNestedMap(1000);
|
HashMap<String, Object> 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)
|
@Test(expected = JSONException.class)
|
||||||
@ -1467,14 +1468,14 @@ public class JSONArrayTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRecursiveDepthArrayForDefaultLevels() {
|
public void testRecursiveDepthArrayForDefaultLevels() {
|
||||||
ArrayList<Object> array = buildNestedArray(JSONParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH);
|
ArrayList<Object> array = buildNestedArray(ParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH);
|
||||||
new JSONArray(array, new JSONParserConfiguration());
|
new JSONArray(array, new JSONParserConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRecursiveDepthArrayFor1000Levels() {
|
public void testRecursiveDepthArrayFor1000Levels() {
|
||||||
ArrayList<Object> array = buildNestedArray(1000);
|
ArrayList<Object> array = buildNestedArray(1000);
|
||||||
JSONParserConfiguration parserConfiguration = new JSONParserConfiguration(1000);
|
JSONParserConfiguration parserConfiguration = new JSONParserConfiguration().withMaxNestingDepth(1000);
|
||||||
new JSONArray(array, parserConfiguration);
|
new JSONArray(array, parserConfiguration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ import org.json.JSONPointerException;
|
|||||||
import org.json.JSONParserConfiguration;
|
import org.json.JSONParserConfiguration;
|
||||||
import org.json.JSONString;
|
import org.json.JSONString;
|
||||||
import org.json.JSONTokener;
|
import org.json.JSONTokener;
|
||||||
|
import org.json.ParserConfiguration;
|
||||||
import org.json.XML;
|
import org.json.XML;
|
||||||
import org.json.junit.data.BrokenToString;
|
import org.json.junit.data.BrokenToString;
|
||||||
import org.json.junit.data.ExceptionalBean;
|
import org.json.junit.data.ExceptionalBean;
|
||||||
@ -3739,7 +3740,7 @@ public class JSONObjectTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void issue743SerializationMapWith512Objects() {
|
public void issue743SerializationMapWith512Objects() {
|
||||||
HashMap<String, Object> map = buildNestedMap(JSONParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH);
|
HashMap<String, Object> map = buildNestedMap(ParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH);
|
||||||
JSONObject object = new JSONObject(map);
|
JSONObject object = new JSONObject(map);
|
||||||
String jsonString = object.toString();
|
String jsonString = object.toString();
|
||||||
}
|
}
|
||||||
@ -3747,7 +3748,7 @@ public class JSONObjectTest {
|
|||||||
@Test
|
@Test
|
||||||
public void issue743SerializationMapWith1000Objects() {
|
public void issue743SerializationMapWith1000Objects() {
|
||||||
HashMap<String, Object> map = buildNestedMap(1000);
|
HashMap<String, Object> map = buildNestedMap(1000);
|
||||||
JSONParserConfiguration parserConfiguration = new JSONParserConfiguration(1000);
|
JSONParserConfiguration parserConfiguration = new JSONParserConfiguration().withMaxNestingDepth(1000);
|
||||||
JSONObject object = new JSONObject(map, parserConfiguration);
|
JSONObject object = new JSONObject(map, parserConfiguration);
|
||||||
String jsonString = object.toString();
|
String jsonString = object.toString();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user