Skip to content

Commit 54b5383

Browse files
committed
root_node_path_exists_fix
1 parent b51d1ad commit 54b5383

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<groupId>com.americanexpress.unify.jdocs</groupId>
2121
<artifactId>unify-jdocs</artifactId>
22-
<version>1.4.0</version>
22+
<version>1.4.1</version>
2323
<packaging>jar</packaging>
2424

2525
<name>unify-jdocs</name>

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ JDocs is available as a jar file in Maven central with the following latest Mave
1515
````pom
1616
<groupId>com.americanexpress.unify.jdocs</groupId>
1717
<artifactId>unify-jdocs</artifactId>
18-
<version>1.4.0</version>
18+
<version>1.4.1</version>
1919
````
2020

2121
---

src/main/java/com/americanexpress/unify/jdocs/JDocument.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,12 @@ private static JsonNode traverseArrayEmpty(JsonNode node, ArrayToken token, bool
663663
// special handling for document that starts with an array
664664
String fieldName = token.getField();
665665
if (fieldName.isEmpty() == true) {
666-
arrayNode = node;
666+
if (node.getNodeType() == JsonNodeType.ARRAY) {
667+
arrayNode = node;
668+
}
669+
else {
670+
arrayNode = null;
671+
}
667672
}
668673
else {
669674
arrayNode = node.get(fieldName);

src/test/java/com/americanexpress/unify/jdocs/DocumentTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,13 @@ void testRootArray() {
904904

905905
s = d.getString("$.[1].cars[1].model");
906906
assertEquals(s, null);
907+
908+
d = new JDocument("{\n" +
909+
" \"response\": \"\",\n" +
910+
" \"status\": 500\n" +
911+
"}");
912+
boolean b = d.pathExists("$.[0].raw_response");
913+
assertEquals(b, false);
907914
}
908915

909916
@Test
Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
1-
package com.americanexpress.unify.jdocs;
1+
/*
2+
* Copyright 2020 American Express Travel Related Services Company, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
214

3-
import java.util.ArrayList;
4-
import java.util.List;
15+
package com.americanexpress.unify.jdocs;
516

17+
/*
18+
* @author Deepak Arora
19+
*/
620
public class TestMisc {
721

822
public static void main(String[] args) {
9-
List<String> paths = new ArrayList<>();
10-
paths.add("$.individuals[00030].addresses[].cars[0098].model");
11-
paths = JsonPathUtils.getNoPaddedIndexes(paths);
12-
paths.stream().forEach(s -> System.out.println(s));
23+
// place holder for test programs
1324
}
1425

1526
}

0 commit comments

Comments
 (0)