Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove-jsonparserconfig-ctor - just use withOverwriteDuplicateKey() #876

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions src/main/java/org/json/JSONParserConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,14 @@ public class JSONParserConfiguration extends ParserConfiguration {
* Configuration with the default values.
*/
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();
this.overwriteDuplicateKey = overwriteDuplicateKey;
this.overwriteDuplicateKey = false;
}

@Override
protected JSONParserConfiguration clone() {
JSONParserConfiguration clone = new JSONParserConfiguration(overwriteDuplicateKey);
JSONParserConfiguration clone = new JSONParserConfiguration();
clone.overwriteDuplicateKey = overwriteDuplicateKey;
clone.maxNestingDepth = maxNestingDepth;
return clone;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public void testThrowException() {

@Test
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"));
}
Expand Down
Loading