Skip to content

Commit

Permalink
Merge pull request #1765 from levoai/master
Browse files Browse the repository at this point in the history
Issue #1764: Handle dereferencing paths accessing arrays by index
  • Loading branch information
gracekarina authored Oct 19, 2022
2 parents af0ab16 + b0838f2 commit 6e83a8b
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,17 @@ public static JsonNode jsonPointerEvaluate(String fragment, JsonNode tree, Strin
String[] tokens = fragment.split("/");
JsonNode node = tree;
for (String token : tokens) {
if (StringUtils.isNotBlank(token)) {
if (StringUtils.isBlank(token)) {
continue;
}
if (node.isArray()) {
node = node.get(Integer.valueOf(token));
} else {
node = node.get(ReferenceUtils.unescapePointer(token));
//if at any point we do find an element we expect, print and error and abort
if (node == null) {
throw new RuntimeException("Could not find " + fragment + " in contents of " + uri);
}
}
//if at any point we do find an element we expect, print and error and abort
if (node == null) {
throw new RuntimeException("Could not find " + fragment + " in contents of " + uri);
}
}
return node;
Expand Down

0 comments on commit 6e83a8b

Please sign in to comment.