Skip to content

Commit

Permalink
issue #345 better error for path segment missing in JSONPointer
Browse files Browse the repository at this point in the history
  • Loading branch information
ryber committed Mar 30, 2020
1 parent e58e132 commit 2c5e2cc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions unirest/src/main/java/kong/unirest/json/JSONPointer.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ public Object queryFrom(Object object) throws JSONPointerException {
Queryable e = verify(object);
Object o = e.querySection(section);
if (next != null) {
if(o == null){
throw new JSONPointerException("Path Segment Missing: " + section);
}
return next.queryFrom(o);
}
return o;
Expand Down
7 changes: 7 additions & 0 deletions unirest/src/test/java/kong/unirest/json/JSONPointerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ public void invalidPathQuery() {
"a JSON pointer should start with '/' or '#/'");
}

@Test
public void invalidPathQuery_downpath() {
TestUtil.assertException(() -> obj.query("/shwoop/dedoop"),
JSONPointerException.class,
"Path Segment Missing: shwoop");
}

@Test
public void arrayPartThatDoesNotExist() {
TestUtil.assertException(() -> obj.query("/foo/5"),
Expand Down

0 comments on commit 2c5e2cc

Please sign in to comment.