Add basic support for using bracket notation in JSON field paths
Previously, only dot notation JSON field paths were supported. Using
dot notation, each key is separated by a '.'. This makes it impossible
to reference a field where the key itself contains a dot.
This commit adds basic bracket notation support to JsonFieldPath.
With this commit, existing functionality remains as is, but users can
now use a basic form of JsonPath bracket notation. This enables the
use of Json keys with embedded dots. i.e. something like :
{
"a.b" : "one"
}
.andDo(document("example",responseFields(fieldWithPath("['a.b']")…
Closes gh-132
This commit is contained in:
@@ -27,6 +27,7 @@ import org.junit.Test;
|
||||
* Tests for {@link JsonFieldPath}
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Jeremy Rickard
|
||||
*/
|
||||
public class JsonFieldPathTests {
|
||||
|
||||
@@ -110,4 +111,19 @@ public class JsonFieldPathTests {
|
||||
contains("[]", "a", "b", "c"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compilationOfMultipleElementPathWithBrackets() {
|
||||
assertThat(JsonFieldPath.compile("['a']['b']['c']").getSegments(), contains("a", "b", "c"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compilationOfMultipleElementPathWithAndWithoutBrackets() {
|
||||
assertThat(JsonFieldPath.compile("['a'][].b['c']").getSegments(), contains("a", "[]", "b", "c"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compilationOfMultipleElementPathWithAndWithoutBracketsAndEmbeddedDots() {
|
||||
assertThat(JsonFieldPath.compile("['a.key'][].b['c']").getSegments(), contains("a.key", "[]", "b", "c"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user