Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonPath.read() ignores REQUIRE_PROPERTIES config option when AS_PATH_LIST is set #143

Closed
bradleymorris opened this issue Oct 21, 2015 · 9 comments

Comments

@bradleymorris
Copy link

Description
When I specify this (Note: REQUIRE_PROPERTIES is NOT set):
Configuration jsonCfg = Configuration.builder().options( Option.AS_PATH_LIST ).build();

And do this:

String jsonStr = "{ \"foo\": { \"bar\" : \"val\" }, \"moo\": { \"cow\" : \"val\" } }";
Predicate[] predicates = {};
DocumentContext dCtx = JsonPath.using( jsonCfg ).parse( jsonStr );
readPaths = dCtx.read( JsonPath.compile( "$.*.bar", predicates ) );

Actual Behaviour
I get this:

Exception in thread "main" com.jayway.jsonpath.PathNotFoundException: No results for path: $['moo']['bar']
    at com.jayway.jsonpath.internal.token.PathToken.handleObjectProperty(PathToken.java:53)
    at com.jayway.jsonpath.internal.token.PropertyPathToken.evaluate(PropertyPathToken.java:44)
    at com.jayway.jsonpath.internal.token.PathToken.handleObjectProperty(PathToken.java:71)
    at com.jayway.jsonpath.internal.token.WildcardPathToken.evaluate(WildcardPathToken.java:32)
    at com.jayway.jsonpath.internal.token.RootPathToken.evaluate(RootPathToken.java:53)
    at com.jayway.jsonpath.internal.CompiledPath.evaluate(CompiledPath.java:53)
    at com.jayway.jsonpath.internal.CompiledPath.evaluate(CompiledPath.java:61)
    at com.jayway.jsonpath.JsonPath.read(JsonPath.java:176)
    at com.jayway.jsonpath.internal.JsonReader.read(JsonReader.java:146)

Expected Behaviour
I expected a List result containing a single path: $[foo].[bar] because I did not have the REQUIRE_PROPERTIES option set. I would only expect to see PathNotFoundException if REQUIRE_PROPERTIES was set.

@bradleymorris
Copy link
Author

Forgot to mention, stepping through with the debugger, it is clear that REQUIRE_PROPERTIES is not being set by default. When I submit the ReadContext.read() request, there is only a single config option in the list - AS_PATH_LIST.

@kallestenflo
Copy link
Contributor

I tried this in version 2.0.0 and 2.1.0 and it works as expected

@Test
public void issue_143() {
    String json = "{ \"foo\": { \"bar\" : \"val\" }, \"moo\": { \"cow\" : \"val\" } }";

    Configuration configuration = Configuration
              .builder()
              .options( Option.AS_PATH_LIST )
              .build();

    List<String> pathList = JsonPath
              .using(configuration)
              .parse(json)
              .read("$.*.bar");

    assertThat(pathList).containsExactly("$['foo']['bar']");
}

What version are you using?

kallestenflo added a commit that referenced this issue Nov 26, 2015
@bradleymorris
Copy link
Author

I am using 2.0.0.

@kallestenflo
Copy link
Contributor

And the test I provided fails?

Sent from my iPhone

On 26 nov. 2015, at 19:28, bradleymorris notifications@github.com wrote:

I am using 2.0.0.


Reply to this email directly or view it on GitHub.

@bradleymorris
Copy link
Author

Yes, this test fails. I had to refactor the assertThat() line to:
Assert.assertThat(pathList, hasItem("$['foo']['bar']"));

...but it does not matter. I get precisely the same Exception and stack trace that I provided in the initial bug description when read() is called.

For the record, 'configuration.jsonProvider().getClass().getName()' tells me I am using the com.jayway.jsonpath.spi.json.JsonSmartJsonProvider.

@jochenberger
Copy link
Contributor

The test works for me too both from Eclipse and shell. @bradleymorris, how do you run the test?

@bradleymorris
Copy link
Author

I am running the test with a JUnit-natured run configuration in Eclipse.

@jochenberger
Copy link
Contributor

I cannot reproduce this. Here's what I do (with current git master):

  • open json-path project in eclipse
  • open com.jayway.jsonpath.old.IssuesTest
  • right-click on the class name and choose Run As -> JUnit Test
    The test completes successfully, including the issue_143 method.

@kallestenflo
Copy link
Contributor

Can not reproduce

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants