|
|
@ -1047,4 +1047,73 @@ public class IssuesTest extends BaseTest { |
|
|
|
|
|
|
|
|
|
|
|
ctx.read(jsonPath); |
|
|
|
ctx.read(jsonPath); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//CS304 (manually written) Issue link: https://github.com/json-path/JsonPath/issues/620
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void issue_620_1(){ |
|
|
|
|
|
|
|
String json = "{\n" + |
|
|
|
|
|
|
|
" \"complexText\": {\n" + |
|
|
|
|
|
|
|
" \"nestedFields\": [\n" + |
|
|
|
|
|
|
|
" {\n" + |
|
|
|
|
|
|
|
" \"index\": \"0\",\n" + |
|
|
|
|
|
|
|
" \"name\": \"A\"\n" + |
|
|
|
|
|
|
|
" },\n" + |
|
|
|
|
|
|
|
" {\n" + |
|
|
|
|
|
|
|
" \"index\": \"1\",\n" + |
|
|
|
|
|
|
|
" \"name\": \"B\"\n" + |
|
|
|
|
|
|
|
" },\n" + |
|
|
|
|
|
|
|
" {\n" + |
|
|
|
|
|
|
|
" \"index\": \"2\",\n" + |
|
|
|
|
|
|
|
" \"name\": \"C\"\n" + |
|
|
|
|
|
|
|
" }\n" + |
|
|
|
|
|
|
|
" ]\n" + |
|
|
|
|
|
|
|
" }\n" + |
|
|
|
|
|
|
|
"}"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String path1 = "$.concat($.complexText.nestedFields[?(@.index == '2')].name," + |
|
|
|
|
|
|
|
"$.complexText.nestedFields[?(@.index == '1')].name," + |
|
|
|
|
|
|
|
"$.complexText.nestedFields[?(@.index == '0')].name)"; |
|
|
|
|
|
|
|
String path2 = "$.concat($.complexText.nestedFields[2].name," + |
|
|
|
|
|
|
|
"$.complexText.nestedFields[1].name," + |
|
|
|
|
|
|
|
"$.complexText.nestedFields[0].name)"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat((String)JsonPath.read(json,path1)).isEqualTo("CBA"); |
|
|
|
|
|
|
|
assertThat((String)JsonPath.read(json,path2)).isEqualTo("CBA"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//CS304 (manually written) Issue link: https://github.com/json-path/JsonPath/issues/620
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void issue_620_2(){ |
|
|
|
|
|
|
|
String json = "{\n" + |
|
|
|
|
|
|
|
" \"complexText\": {\n" + |
|
|
|
|
|
|
|
" \"nestedFields\": [\n" + |
|
|
|
|
|
|
|
" {\n" + |
|
|
|
|
|
|
|
" \"index\": \"0\",\n" + |
|
|
|
|
|
|
|
" \"name\": \"A\"\n" + |
|
|
|
|
|
|
|
" },\n" + |
|
|
|
|
|
|
|
" {\n" + |
|
|
|
|
|
|
|
" \"index\": \"1\",\n" + |
|
|
|
|
|
|
|
" \"name\": \"B\"\n" + |
|
|
|
|
|
|
|
" },\n" + |
|
|
|
|
|
|
|
" {\n" + |
|
|
|
|
|
|
|
" \"index\": \"2\",\n" + |
|
|
|
|
|
|
|
" \"name\": \"C\"\n" + |
|
|
|
|
|
|
|
" }\n" + |
|
|
|
|
|
|
|
" ]\n" + |
|
|
|
|
|
|
|
" }\n" + |
|
|
|
|
|
|
|
"}"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String path1 = "$.concat($.complexText.nestedFields[?(@.index == '2')].name," + |
|
|
|
|
|
|
|
"$.complexText.nestedFields[?((@.index == '1')].name," + |
|
|
|
|
|
|
|
"$.complexText.nestedFields[?(@.index == '0')].name)"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean thrown = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
Object result = (Object) JsonPath.read(json,path1); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
thrown = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertTrue(thrown); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|