Skip to content

Commit

Permalink
Merge pull request #942 from michael-ameri/fix-clone
Browse files Browse the repository at this point in the history
add missing fields when cloning JSONParserConfiguration
  • Loading branch information
stleary authored Jan 19, 2025
2 parents 1d81e88 + 4bbbe77 commit 07b1291
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/main/java/org/json/JSONParserConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public JSONParserConfiguration() {
protected JSONParserConfiguration clone() {
JSONParserConfiguration clone = new JSONParserConfiguration();
clone.overwriteDuplicateKey = overwriteDuplicateKey;
clone.strictMode = strictMode;
clone.maxNestingDepth = maxNestingDepth;
clone.keepStrings = keepStrings;
return clone;
}

Expand Down
23 changes: 22 additions & 1 deletion src/test/java/org/json/junit/JSONParserConfigurationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

public class JSONParserConfigurationTest {
private static final String TEST_SOURCE = "{\"key\": \"value1\", \"key\": \"value2\"}";
Expand All @@ -33,6 +36,24 @@ public void testOverwrite() {
assertEquals("duplicate key should be overwritten", "value2", jsonObject.getString("key"));
}

@Test
public void strictModeIsCloned(){
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration()
.withStrictMode(true)
.withMaxNestingDepth(12);

assertTrue(jsonParserConfiguration.isStrictMode());
}

@Test
public void maxNestingDepthIsCloned(){
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration()
.<JSONParserConfiguration>withKeepStrings(true)
.withStrictMode(true);

assertTrue(jsonParserConfiguration.isKeepStrings());
}

@Test
public void verifyDuplicateKeyThenMaxDepth() {
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration()
Expand Down

0 comments on commit 07b1291

Please sign in to comment.