Skip to content

Commit

Permalink
root_node_path_exists_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakarora3 committed Aug 15, 2023
1 parent b51d1ad commit 54b5383
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<groupId>com.americanexpress.unify.jdocs</groupId>
<artifactId>unify-jdocs</artifactId>
<version>1.4.0</version>
<version>1.4.1</version>
<packaging>jar</packaging>

<name>unify-jdocs</name>
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ JDocs is available as a jar file in Maven central with the following latest Mave
````pom
<groupId>com.americanexpress.unify.jdocs</groupId>
<artifactId>unify-jdocs</artifactId>
<version>1.4.0</version>
<version>1.4.1</version>
````

---
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/americanexpress/unify/jdocs/JDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,12 @@ private static JsonNode traverseArrayEmpty(JsonNode node, ArrayToken token, bool
// special handling for document that starts with an array
String fieldName = token.getField();
if (fieldName.isEmpty() == true) {
arrayNode = node;
if (node.getNodeType() == JsonNodeType.ARRAY) {
arrayNode = node;
}
else {
arrayNode = null;
}
}
else {
arrayNode = node.get(fieldName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,13 @@ void testRootArray() {

s = d.getString("$.[1].cars[1].model");
assertEquals(s, null);

d = new JDocument("{\n" +
" \"response\": \"\",\n" +
" \"status\": 500\n" +
"}");
boolean b = d.pathExists("$.[0].raw_response");
assertEquals(b, false);
}

@Test
Expand Down
25 changes: 18 additions & 7 deletions src/test/java/com/americanexpress/unify/jdocs/TestMisc.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
package com.americanexpress.unify.jdocs;
/*
* Copyright 2020 American Express Travel Related Services Company, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

import java.util.ArrayList;
import java.util.List;
package com.americanexpress.unify.jdocs;

/*
* @author Deepak Arora
*/
public class TestMisc {

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

}

0 comments on commit 54b5383

Please sign in to comment.