You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
37 lines
1.1 KiB
package com.jayway.jsonpath.issue; |
|
|
|
import com.jayway.jsonpath.JsonPath; |
|
import com.jayway.jsonpath.ReadContext; |
|
import org.junit.Test; |
|
|
|
import java.util.List; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
import static org.junit.Assert.assertNotNull; |
|
|
|
public class Issue565 { |
|
|
|
@Test |
|
public void test_issue_565() { |
|
String json = "{\n" + |
|
" \"oldName\": {\n" + |
|
" \"oldName\": {\n" + |
|
" \"oldName\": {\n" + |
|
" \"otherName\": \"value\"\n" + |
|
" }\n" + |
|
" }\n" + |
|
" }\n" + |
|
"}"; |
|
String jsonPath = "$..[?(@.oldName)]"; |
|
String oldKeyName = "oldName"; |
|
String newKeyName = "newName"; |
|
ReadContext context = JsonPath.parse(json).renameKey(jsonPath, oldKeyName, newKeyName); |
|
List<Object> result = context.read("$..[?(@.newName)]"); |
|
|
|
assertEquals(3, result.size()); |
|
|
|
assertNotNull(context.read("$.newName")); |
|
assertNotNull(context.read("$.newName.newName")); |
|
assertNotNull(context.read("$.newName.newName.newName")); |
|
} |
|
}
|
|
|