diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/CharacterIndex.java b/json-path/src/main/java/com/jayway/jsonpath/internal/CharacterIndex.java index 72da4ffc..5e358af2 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/CharacterIndex.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/CharacterIndex.java @@ -3,7 +3,6 @@ package com.jayway.jsonpath.internal; import com.jayway.jsonpath.InvalidPathException; public class CharacterIndex { - private static final char OPEN_PARENTHESIS = '('; private static final char CLOSE_PARENTHESIS = ')'; private static final char CLOSE_SQUARE_BRACKET = ']'; @@ -29,6 +28,7 @@ public class CharacterIndex { this.endPosition = charSequence.length() - 1; } + public int length() { return endPosition + 1; } @@ -320,4 +320,15 @@ public class CharacterIndex { skipBlanksAtEnd(); return this; } + + public void readWhitespace() { + while (inBounds()) { + char c = currentChar(); + if (!Character.isWhitespace(c)) { + break; + } + incrementPosition(1); + } + } + } diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java b/json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java index a9cc86cb..ec3f4a7a 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java @@ -85,13 +85,7 @@ public class PathCompiler { } private void readWhitespace() { - while (path.inBounds()) { - char c = path.currentChar(); - if (!isWhitespace(c)) { - break; - } - path.incrementPosition(1); - } + path.readWhitespace(); } private Boolean isPathContext(char c) { @@ -101,7 +95,7 @@ public class PathCompiler { //[$ | @] private RootPathToken readContextToken() { - readWhitespace(); + path.readWhitespace(); if (!isPathContext(path.currentChar())) { throw new InvalidPathException("Path must start with '$' or '@'"); diff --git a/json-path/src/test/java/com/jayway/jsonpath/Configurations.java b/json-path/src/test/java/com/jayway/jsonpath/Configurations.java index 537d2be0..cd89b2db 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/Configurations.java +++ b/json-path/src/test/java/com/jayway/jsonpath/Configurations.java @@ -16,37 +16,37 @@ import java.util.Arrays; public class Configurations { - public static final Configuration JSON_ORG_CONFIGURATION = Configuration + private static final Configuration JSON_ORG_CONFIGURATION = Configuration .builder() .mappingProvider(new JsonOrgMappingProvider()) .jsonProvider(new JsonOrgJsonProvider()) .build(); - public static final Configuration GSON_CONFIGURATION = Configuration + private static final Configuration GSON_CONFIGURATION = Configuration .builder() .mappingProvider(new GsonMappingProvider()) .jsonProvider(new GsonJsonProvider()) .build(); - public static final Configuration JACKSON_CONFIGURATION = Configuration + private static final Configuration JACKSON_CONFIGURATION = Configuration .builder() .mappingProvider(new JacksonMappingProvider()) .jsonProvider(new JacksonJsonProvider()) .build(); - public static final Configuration JACKSON_JSON_NODE_CONFIGURATION = Configuration + private static final Configuration JACKSON_JSON_NODE_CONFIGURATION = Configuration .builder() .mappingProvider(new JacksonMappingProvider()) .jsonProvider(new JacksonJsonNodeJsonProvider()) .build(); - public static final Configuration JSON_SMART_CONFIGURATION = Configuration + private static final Configuration JSON_SMART_CONFIGURATION = Configuration .builder() .mappingProvider(new JsonSmartMappingProvider()) .jsonProvider(new JsonSmartJsonProvider()) .build(); - public static final Configuration JAKARTA_CONFIGURATION = Configuration + private static final Configuration JAKARTA_CONFIGURATION = Configuration .builder() .mappingProvider(new JakartaMappingProvider()) .jsonProvider(new JakartaJsonProvider()) @@ -54,21 +54,46 @@ public class Configurations { public static Iterable configurations() { return Arrays.asList( - JSON_SMART_CONFIGURATION - ,GSON_CONFIGURATION - ,JACKSON_CONFIGURATION - ,JACKSON_JSON_NODE_CONFIGURATION - ,JSON_ORG_CONFIGURATION - ,JAKARTA_CONFIGURATION + JSON_SMART_CONFIGURATION, + GSON_CONFIGURATION, + JACKSON_CONFIGURATION, + JACKSON_JSON_NODE_CONFIGURATION, + JSON_ORG_CONFIGURATION, + JAKARTA_CONFIGURATION ); } public static Iterable objectMappingConfigurations() { return Arrays.asList( - GSON_CONFIGURATION - ,JACKSON_CONFIGURATION - ,JACKSON_JSON_NODE_CONFIGURATION - ,JAKARTA_CONFIGURATION + GSON_CONFIGURATION, + JACKSON_CONFIGURATION, + JACKSON_JSON_NODE_CONFIGURATION, + JAKARTA_CONFIGURATION ); } + + // Public getter methods for accessing configurations + public static Configuration getJsonOrgConfiguration() { + return JSON_ORG_CONFIGURATION; + } + + public static Configuration getGsonConfiguration() { + return GSON_CONFIGURATION; + } + + public static Configuration getJacksonConfiguration() { + return JACKSON_CONFIGURATION; + } + + public static Configuration getJacksonJsonNodeConfiguration() { + return JACKSON_JSON_NODE_CONFIGURATION; + } + + public static Configuration getJsonSmartConfiguration() { + return JSON_SMART_CONFIGURATION; + } + + public static Configuration getJakartaConfiguration() { + return JAKARTA_CONFIGURATION; + } } diff --git a/json-path/src/test/java/com/jayway/jsonpath/internal/function/Issue191.java b/json-path/src/test/java/com/jayway/jsonpath/internal/function/Issue191.java index 010ef96f..483c6f1d 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/internal/function/Issue191.java +++ b/json-path/src/test/java/com/jayway/jsonpath/internal/function/Issue191.java @@ -16,7 +16,8 @@ import java.io.InputStream; */ public class Issue191 { - private Configuration conf = Configurations.GSON_CONFIGURATION; + private Configuration conf = Configurations.getGsonConfiguration(); + @Test public void testResultSetNumericComputation() { diff --git a/json-path/src/test/java/com/jayway/jsonpath/internal/function/JSONEntityPathFunctionTest.java b/json-path/src/test/java/com/jayway/jsonpath/internal/function/JSONEntityPathFunctionTest.java index 4c6dff22..97b5a9af 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/internal/function/JSONEntityPathFunctionTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/internal/function/JSONEntityPathFunctionTest.java @@ -52,7 +52,8 @@ public class JSONEntityPathFunctionTest extends BaseFunctionTest { - private Configuration conf = Configurations.JSON_SMART_CONFIGURATION; + + private Configuration conf= Configurations.getJsonSmartConfiguration(); @Test public void testLengthOfTextArray() { diff --git a/json-path/src/test/java/com/jayway/jsonpath/internal/function/KeySetFunctionTest.java b/json-path/src/test/java/com/jayway/jsonpath/internal/function/KeySetFunctionTest.java index 0d52202b..7c4770f0 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/internal/function/KeySetFunctionTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/internal/function/KeySetFunctionTest.java @@ -14,7 +14,7 @@ import java.util.HashSet; */ public class KeySetFunctionTest extends BaseFunctionTest { - private Configuration conf = Configurations.JACKSON_CONFIGURATION; + private Configuration conf = Configurations.getJsonSmartConfiguration(); @Test public void testKeySet() throws Exception { diff --git a/json-path/src/test/java/com/jayway/jsonpath/internal/function/SequentialPathFunctionTest.java b/json-path/src/test/java/com/jayway/jsonpath/internal/function/SequentialPathFunctionTest.java index d3785dc2..6d8d4e37 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/internal/function/SequentialPathFunctionTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/internal/function/SequentialPathFunctionTest.java @@ -15,7 +15,7 @@ import org.junit.jupiter.api.Test; */ public class SequentialPathFunctionTest extends BaseFunctionTest { - private Configuration conf = Configurations.JACKSON_CONFIGURATION; + private Configuration conf = Configurations.getJsonSmartConfiguration(); @Test public void testFirstOfNumbers() throws Exception {