7 changed files with 145 additions and 2 deletions
@ -0,0 +1,38 @@ |
|||||||
|
package com.jayway.jsonpath.internal.function; |
||||||
|
|
||||||
|
import net.minidev.json.JSONArray; |
||||||
|
import com.jayway.jsonpath.JsonPath; |
||||||
|
import org.junit.Test; |
||||||
|
import java.io.InputStream; |
||||||
|
import java.util.LinkedHashMap; |
||||||
|
import static org.junit.Assert.assertEquals; |
||||||
|
import static org.junit.Assert.assertNotNull; |
||||||
|
|
||||||
|
public class Issue394 { |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testGetParentNodeByChildNodeFromStream(){ |
||||||
|
InputStream stream = ClassLoader.getSystemResourceAsStream("issue_394.json"); |
||||||
|
|
||||||
|
JSONArray arr = JsonPath.parse(stream).read("$.street.store.book[?(@.authors[?(@.lastName == 'Waugh')])]"); |
||||||
|
|
||||||
|
assertEquals(arr.size(),1); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testGetParentNodeByChildNodeFromJson(){ |
||||||
|
String json = "{\n" + |
||||||
|
" \"parent\": {\n" + |
||||||
|
" \"children\": [\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}"; |
||||||
|
|
||||||
|
JSONArray arr = JsonPath.read(json,"$.parent[?(@.children[?(@.index == '2')])]"); |
||||||
|
|
||||||
|
assertNotNull(((LinkedHashMap) arr.get(0)).get("children")); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,75 @@ |
|||||||
|
{ |
||||||
|
"street": { |
||||||
|
"store": { |
||||||
|
"book": [ |
||||||
|
{ |
||||||
|
"category": "reference", |
||||||
|
"authors": [ |
||||||
|
{ |
||||||
|
"firstName": "Nigel", |
||||||
|
"lastName": "Rees" |
||||||
|
}, |
||||||
|
{ |
||||||
|
"firstName": "Evelyn", |
||||||
|
"lastName": "Waugh" |
||||||
|
} |
||||||
|
], |
||||||
|
"title": "Sayings of the Century", |
||||||
|
"price": 8.95 |
||||||
|
}, |
||||||
|
{ |
||||||
|
"category": "fiction", |
||||||
|
"authors": [ |
||||||
|
{ |
||||||
|
"firstName": "A", |
||||||
|
"lastName": "B" |
||||||
|
}, |
||||||
|
{ |
||||||
|
"firstName": "C", |
||||||
|
"lastName": "D" |
||||||
|
} |
||||||
|
], |
||||||
|
"title": "Sword of Honour", |
||||||
|
"price": 12.99 |
||||||
|
}, |
||||||
|
{ |
||||||
|
"category": "fiction", |
||||||
|
"authors": [ |
||||||
|
{ |
||||||
|
"firstName": "A", |
||||||
|
"lastName": "D" |
||||||
|
}, |
||||||
|
{ |
||||||
|
"firstName": "Evelyn", |
||||||
|
"lastName": "X" |
||||||
|
} |
||||||
|
], |
||||||
|
"title": "Moby Dick", |
||||||
|
"isbn": "0-553-21311-3", |
||||||
|
"price": 8.99 |
||||||
|
}, |
||||||
|
{ |
||||||
|
"category": "fiction", |
||||||
|
"authors": [ |
||||||
|
{ |
||||||
|
"firstName": "Nigel", |
||||||
|
"lastName": "Rees" |
||||||
|
}, |
||||||
|
{ |
||||||
|
"firstName": "Evelyn", |
||||||
|
"lastName": "X" |
||||||
|
} |
||||||
|
], |
||||||
|
"title": "The Lord of the Rings", |
||||||
|
"isbn": "0-395-19395-8", |
||||||
|
"price": 22.99 |
||||||
|
} |
||||||
|
], |
||||||
|
"bicycle": { |
||||||
|
"color": "red", |
||||||
|
"price": 19.95 |
||||||
|
} |
||||||
|
}, |
||||||
|
"expensive": 10 |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue