@Test public void canGetFieldsWithinArrayElementObjects() { assertThat(new NodePath("array2[0].arrayObjectField1").findMatchingDescendant(root), matches(isTextNode("abc"))); assertThat(new NodePath("array2[0].arrayObjectField2").findMatchingDescendant(root), matches(isTextNode("def"))); }
public Optional<JsonNode> findMatchingDescendant(JsonNode rootNode) { JsonNode current = rootNode; for (PathElement element : elements) { current = element.child(current); if (current == null) { return Optional.empty(); } } return Optional.ofNullable(current); }
NodePath { public Optional<JsonNode> findMatchingDescendant(JsonNode rootNode) { JsonNode current = rootNode; for (PathElement element : elements) { current = element.child(current); if (current == null) { return Optional.empty(); } } return Optional.ofNullable(current); } }
NodePath { public Optional<JsonNode> findMatchingDescendant(JsonNode rootNode) { JsonNode current = rootNode; for (PathElement element : elements) { current = element.child(current); if (current == null) { return Optional.empty(); } } return Optional.ofNullable(current); } NodePath(String path);   NodePath(List<PathElement> elements); }
NodePath { public Optional<JsonNode> findMatchingDescendant(JsonNode rootNode) { JsonNode current = rootNode; for (PathElement element : elements) { current = element.child(current); if (current == null) { return Optional.empty(); } } return Optional.ofNullable(current); } NodePath(String path);   NodePath(List<PathElement> elements); List<PathElement> elements(); PathElement lastElement(); Optional<JsonNode> findMatchingDescendant(JsonNode rootNode); boolean override(JsonNode rootNode, JsonNode leaf); boolean override(JsonNode rootNode, String value); @Override String toString(); }
NodePath { public Optional<JsonNode> findMatchingDescendant(JsonNode rootNode) { JsonNode current = rootNode; for (PathElement element : elements) { current = element.child(current); if (current == null) { return Optional.empty(); } } return Optional.ofNullable(current); } NodePath(String path);   NodePath(List<PathElement> elements); List<PathElement> elements(); PathElement lastElement(); Optional<JsonNode> findMatchingDescendant(JsonNode rootNode); boolean override(JsonNode rootNode, JsonNode leaf); boolean override(JsonNode rootNode, String value); @Override String toString();  }