-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Duplicate key check in JacksonJrsTreeCodec (#127)
- Loading branch information
Showing
6 changed files
with
63 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
jr-stree/src/test/java/com/fasterxml/jackson/jr/stree/DupFieldNameInTree51Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.fasterxml.jackson.jr.stree; | ||
|
||
import com.fasterxml.jackson.jr.ob.JSON; | ||
import com.fasterxml.jackson.jr.ob.JSONObjectException; | ||
|
||
/** | ||
* Tests for reading content using {@link JSON} with proper | ||
* codec registration | ||
*/ | ||
public class DupFieldNameInTree51Test extends JacksonJrTreeTestBase | ||
{ | ||
private final JSON NO_DUPS_JSON = JSON.builder() | ||
.enable(JSON.Feature.FAIL_ON_DUPLICATE_MAP_KEYS) | ||
.register(new JrSimpleTreeExtension()) | ||
.build(); | ||
|
||
private final JSON DUPS_OK_JSON = JSON.builder() | ||
.disable(JSON.Feature.FAIL_ON_DUPLICATE_MAP_KEYS) | ||
.register(new JrSimpleTreeExtension()) | ||
.build(); | ||
|
||
// [jackson-jr#51]: test dup keys for trees too | ||
public void testFailOnDupMapKeys() throws Exception | ||
{ | ||
assertTrue(NO_DUPS_JSON.isEnabled(JSON.Feature.FAIL_ON_DUPLICATE_MAP_KEYS)); | ||
final String json = "{\"a\":1,\"b\":2,\"b\":3,\"c\":4}"; | ||
try { | ||
/*TreeNode node =*/ NO_DUPS_JSON.treeFrom(json); | ||
fail("Should not pass"); | ||
} catch (JSONObjectException e) { | ||
verifyException(e, "Duplicate key"); | ||
} | ||
|
||
assertFalse(DUPS_OK_JSON.isEnabled(JSON.Feature.FAIL_ON_DUPLICATE_MAP_KEYS)); | ||
// But should pass fine without setting | ||
assertNotNull(DUPS_OK_JSON.treeFrom(json)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
jr-stree/src/test/java/com/fasterxml/jackson/jr/stree/failing/DupFieldNameInTree51Test.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters