mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-03 03:15:32 -04:00
Merge pull request #876 from stleary/remove-jsonparserconfig-ctor
remove-jsonparserconfig-ctor - just use withOverwriteDuplicateKey()
This commit is contained in:
commit
48c092acfb
@ -13,24 +13,14 @@ public class JSONParserConfiguration extends ParserConfiguration {
|
|||||||
* Configuration with the default values.
|
* Configuration with the default values.
|
||||||
*/
|
*/
|
||||||
public JSONParserConfiguration() {
|
public JSONParserConfiguration() {
|
||||||
this(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configure the parser with argument overwriteDuplicateKey.
|
|
||||||
*
|
|
||||||
* @param overwriteDuplicateKey Indicate whether to overwrite duplicate key or not.<br>
|
|
||||||
* If not, the JSONParser will throw a {@link JSONException}
|
|
||||||
* when meeting duplicate keys.
|
|
||||||
*/
|
|
||||||
public JSONParserConfiguration(boolean overwriteDuplicateKey) {
|
|
||||||
super();
|
super();
|
||||||
this.overwriteDuplicateKey = overwriteDuplicateKey;
|
this.overwriteDuplicateKey = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JSONParserConfiguration clone() {
|
protected JSONParserConfiguration clone() {
|
||||||
JSONParserConfiguration clone = new JSONParserConfiguration(overwriteDuplicateKey);
|
JSONParserConfiguration clone = new JSONParserConfiguration();
|
||||||
|
clone.overwriteDuplicateKey = overwriteDuplicateKey;
|
||||||
clone.maxNestingDepth = maxNestingDepth;
|
clone.maxNestingDepth = maxNestingDepth;
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,8 @@ public class JSONParserConfigurationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOverwrite() {
|
public void testOverwrite() {
|
||||||
JSONObject jsonObject = new JSONObject(TEST_SOURCE, new JSONParserConfiguration(true));
|
JSONObject jsonObject = new JSONObject(TEST_SOURCE,
|
||||||
|
new JSONParserConfiguration().withOverwriteDuplicateKey(true));
|
||||||
|
|
||||||
assertEquals("duplicate key should be overwritten", "value2", jsonObject.getString("key"));
|
assertEquals("duplicate key should be overwritten", "value2", jsonObject.getString("key"));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user