From dab29ec1d537c3f2f124fe1505f56b9756b45b33 Mon Sep 17 00:00:00 2001 From: Sean Leary Date: Sat, 9 Mar 2024 09:15:53 -0600 Subject: [PATCH] remove-jsonparserconfig-ctor - just use the withOverwriteDuplicateKey() method --- .../java/org/json/JSONParserConfiguration.java | 16 +++------------- .../json/junit/JSONParserConfigurationTest.java | 3 ++- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/json/JSONParserConfiguration.java b/src/main/java/org/json/JSONParserConfiguration.java index fc16f61..190daeb 100644 --- a/src/main/java/org/json/JSONParserConfiguration.java +++ b/src/main/java/org/json/JSONParserConfiguration.java @@ -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.
- * 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; } diff --git a/src/test/java/org/json/junit/JSONParserConfigurationTest.java b/src/test/java/org/json/junit/JSONParserConfigurationTest.java index 0e80d77..509b988 100644 --- a/src/test/java/org/json/junit/JSONParserConfigurationTest.java +++ b/src/test/java/org/json/junit/JSONParserConfigurationTest.java @@ -18,7 +18,8 @@ public class JSONParserConfigurationTest { @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")); }