json-path / JsonPath

Java JsonPath implementation
Apache License 2.0
8.95k stars 1.65k forks source link

Fix logic of parsing function with no arguments. #990

Open q2w opened 10 months ago

q2w commented 10 months ago

Currently a function with no arguments is not parsed correctly. Given $.objects.keys().size(), after encountering keys (a function with no arguments) the position should move from $.objects.keys().size() to $.objects.keys().size(). But in current implementation read position moves from $.objects.keys().size() to $.objects.keys().size()

This pull request will fix the issue.

q2w commented 10 months ago

@kallestenflo

kallestenflo commented 9 months ago

Please provide a test in your PR that demonstrates a case.

q2w commented 9 months ago

@kallestenflo Thanks! I have added a test case for the same.

Json:

"{\"empty\": [], \"number-series\" : [[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [11, 12]]}"

JsonPath: "$.number-series.first().last()"

Before this change, the test case is failing with below error.

Expected to find an object with property [')'] in path $['number-series'] but found 'net.minidev.json.JSONArray'. This is not a json object according to the JsonProvider: 'com.jayway.jsonpath.spi.json.JsonSmartJsonProvider'.
com.jayway.jsonpath.PathNotFoundException: Expected to find an object with property [')'] in path $['number-series'] but found 'net.minidev.json.JSONArray'. This is not a json object according to the JsonProvider: 'com.jayway.jsonpath.spi.json.JsonSmartJsonProvider'.
q2w commented 9 months ago

@kallestenflo