diff --git a/pom.xml b/pom.xml index 56e3a72..f98e9a0 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ com.americanexpress.unify.jdocs unify-jdocs - 1.4.0 + 1.4.1 jar unify-jdocs diff --git a/readme.md b/readme.md index 4b5dbc3..c2bbed2 100644 --- a/readme.md +++ b/readme.md @@ -15,7 +15,7 @@ JDocs is available as a jar file in Maven central with the following latest Mave ````pom com.americanexpress.unify.jdocs unify-jdocs -1.4.0 +1.4.1 ```` --- diff --git a/src/main/java/com/americanexpress/unify/jdocs/JDocument.java b/src/main/java/com/americanexpress/unify/jdocs/JDocument.java index c18e067..27139a4 100644 --- a/src/main/java/com/americanexpress/unify/jdocs/JDocument.java +++ b/src/main/java/com/americanexpress/unify/jdocs/JDocument.java @@ -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); diff --git a/src/test/java/com/americanexpress/unify/jdocs/DocumentTest.java b/src/test/java/com/americanexpress/unify/jdocs/DocumentTest.java index 0d386ae..aff309f 100644 --- a/src/test/java/com/americanexpress/unify/jdocs/DocumentTest.java +++ b/src/test/java/com/americanexpress/unify/jdocs/DocumentTest.java @@ -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 diff --git a/src/test/java/com/americanexpress/unify/jdocs/TestMisc.java b/src/test/java/com/americanexpress/unify/jdocs/TestMisc.java index e617174..a82d0bd 100644 --- a/src/test/java/com/americanexpress/unify/jdocs/TestMisc.java +++ b/src/test/java/com/americanexpress/unify/jdocs/TestMisc.java @@ -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 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 } }