forked from json-path/JsonPath
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
json-path#1016 Fixed that issue by adding support for Maps and JSONAr…
…ray to toValueNode. Added tests.
- Loading branch information
DK
committed
Jul 30, 2024
1 parent
45333e0
commit a2c1d9b
Showing
2 changed files
with
59 additions
and
2 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
52 changes: 52 additions & 0 deletions
52
json-path/src/test/java/com/jayway/jsonpath/Issue_1016.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,52 @@ | ||
package com.jayway.jsonpath; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
|
||
public class Issue_1016 | ||
{ | ||
public static final Configuration jsonConf = Configuration.defaultConfiguration(); | ||
|
||
@Test | ||
public void test_read_with_empty_array() | ||
{ | ||
// Before fix: | ||
// assertEvaluationThrows("[{\"id\":1,\"array\":[\"a\",{\"b\":\"c\"}]}]", "$.*[?(\"a\" in @.array)]", JsonPathException.class); | ||
|
||
DocumentContext emptyArray = JsonPath.using(jsonConf).parse("[{\"id\":1,\"array\":[\"a\",[]]}]"); | ||
Object read = emptyArray.read("$.*[?(\"a\" in @.array)]"); | ||
assert(read.toString().equals("[{\"id\":1,\"array\":[\"a\",[]]}]")); | ||
} | ||
|
||
@Test | ||
public void test_read_with_filled_array() | ||
{ | ||
DocumentContext filledArray = JsonPath.using(jsonConf).parse("[{\"id\":1,\"array\":[\"a\",[\"b\", \"c\"]]}]"); | ||
Object read = filledArray.read("$.*[?(\"a\" in @.array)]"); | ||
assert(read.toString().equals("[{\"id\":1,\"array\":[\"a\",[\"b\",\"c\"]]}]")); | ||
} | ||
|
||
@Test | ||
public void test_read_with_empty_object() | ||
{ | ||
DocumentContext emptyObj = JsonPath.using(jsonConf).parse("[{\"id\":1,\"array\":[\"a\",{}]}]"); | ||
Object read = emptyObj.read("$.*[?(\"a\" in @.array)]"); | ||
assert(read.toString().equals("[{\"id\":1,\"array\":[\"a\",{}]}]")); | ||
} | ||
|
||
@Test | ||
public void test_read_with_filled_object() | ||
{ | ||
DocumentContext filledObj = JsonPath.using(jsonConf).parse("[{\"id\":1,\"array\":[\"a\",{\"b\":\"c\"}]}]"); | ||
Object read = filledObj.read("$.*[?(\"a\" in @.array)]"); | ||
assert(read.toString().equals("[{\"id\":1,\"array\":[\"a\",{\"b\":\"c\"}]}]")); | ||
} | ||
|
||
@Test | ||
public void test_read_with_combined_elements() | ||
{ | ||
DocumentContext combined = JsonPath.using(jsonConf).parse("[{\"id\":1,\"array\":[\"a\",[\"b\", {\"c\" : \"d\"}]]}]"); | ||
Object read = combined.read("$.*[?(\"a\" in @.array)]"); | ||
assert(read.toString().equals("[{\"id\":1,\"array\":[\"a\",[\"b\",{\"c\":\"d\"}]]}]")); | ||
} | ||
} |