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

Regression in JacksonJsonNodeJsonProvider #366

Closed
trustin opened this issue Jun 29, 2017 · 7 comments
Closed

Regression in JacksonJsonNodeJsonProvider #366

trustin opened this issue Jun 29, 2017 · 7 comments

Comments

@trustin
Copy link

trustin commented Jun 29, 2017

Given the following document:

[
  {
    "name": "a",
    "groups": [{
      "type": "phase",
      "name": "alpha"
    }, {
      "type": "not_phase",
      "name": "beta"
    }]
  }, {
    "name": "b",
    "groups": [{
      "type": "phase",
      "name": "beta"
    }, {
      "type": "not_phase",
      "name": "alpha"
    }]
  }
]

and the following JSON path query:

$[?(@.groups[?(@.type == 'phase' && @.name == 'alpha')] empty false)]

2.2.0 and 2.3.0 yield different results:

// 2.2.0 (selects 'a'):
[
  {
    "name": "a",
    "groups": [{
      "type": "phase",
      "name": "alpha"
    }, {
      "type": "not_phase",
      "name": "beta"
    }]
  }
]
// 2.3.0 (selects none):
[]
@jochenberger
Copy link
Contributor

I can't reproduce the issue. I get the same result with 2.2.0 and 2.3.0. Can you share some more details?

@trustin
Copy link
Author

trustin commented Jun 29, 2017

That's weird. Let me dig further and get back to you.

@trustin
Copy link
Author

trustin commented Jun 29, 2017

Could you try this?

import org.junit.Test;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider;
import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;

public class Regression366 {
    @Test
    public void regression() throws Exception {
        JsonNode instance = new ObjectMapper().readTree(
                '[' +
                "  {" +
                "    \"name\": \"a\"," +
                "    \"groups\": [{" +
                "      \"type\": \"phase\"," +
                "      \"name\": \"alpha\"" +
                "    }, {" +
                "      \"type\": \"not_phase\"," +
                "      \"name\": \"beta\"" +
                "    }]" +
                "  }, {" +
                "    \"name\": \"b\"," +
                "    \"groups\": [{" +
                "      \"type\": \"phase\"," +
                "      \"name\": \"beta\"" +
                "    }, {" +
                "      \"type\": \"not_phase\"," +
                "      \"name\": \"alpha\"" +
                "    }]" +
                "  }" +
                ']');

        Configuration jsonPathConf =
                Configuration.builder()
                             .jsonProvider(new JacksonJsonNodeJsonProvider(new ObjectMapper()))
                             .mappingProvider(new JacksonMappingProvider(new ObjectMapper())).build();

        // Should not print '[]'
        System.err.println(
                JsonPath.parse(instance, jsonPathConf)
                        .read(JsonPath.compile(
                                "$[?(@.groups[?(@.type == 'phase' && @.name == 'alpha')] empty false)]"),
                              JsonNode.class));
    }
}

@trustin
Copy link
Author

trustin commented Jun 29, 2017

It seems like the following queries did not regress though:

  • $[?(@.name == 'b')]
  • $..groups[?(@.type == 'not_phase' && @.name == 'alpha')]

.. making me guess that there's something going wrong with nested queries.

@jochenberger
Copy link
Contributor

jochenberger commented Jun 29, 2017

It seems to be related to the JacksonJsonNodeJsonProvider:

 String json = "[  {    \"name\": \"a\",    \"groups\": [{      \"type\": \"phase\","
        + "      \"name\": \"alpha\"    }, {      \"type\": \"not_phase\",      \"name\": \"beta\""
        + "    }]  }, {    \"name\": \"b\",    \"groups\": [{      \"type\": \"phase\","
        + "      \"name\": \"beta\"    }, {      \"type\": \"not_phase\",      \"name\": \"alpha\"" + "    }]  }]";

    // Should not print '[]'
    System.err.println(JsonPath.parse(json)
        .read(JsonPath.compile("$[?(@.groups[?(@.type == 'phase' && @.name == 'alpha')] empty false)]")));

yields the same result with 2.2.0 and 2.3.0.
So does

String json = "[  {    \"name\": \"a\",    \"groups\": [{      \"type\": \"phase\","
        + "      \"name\": \"alpha\"    }, {      \"type\": \"not_phase\",      \"name\": \"beta\""
        + "    }]  }, {    \"name\": \"b\",    \"groups\": [{      \"type\": \"phase\","
        + "      \"name\": \"beta\"    }, {      \"type\": \"not_phase\",      \"name\": \"alpha\"" + "    }]  }]";

    Configuration jsonPathConf = Configuration.builder().jsonProvider(new JacksonJsonProvider(new ObjectMapper()))
        .mappingProvider(new JacksonMappingProvider(new ObjectMapper())).build();

    // Should not print '[]'
    System.err.println(JsonPath.using(jsonPathConf).parse(json)
        .read(JsonPath.compile("$[?(@.groups[?(@.type == 'phase' && @.name == 'alpha')] empty false)]")));

@jochenberger
Copy link
Contributor

jochenberger commented Jun 29, 2017

6cf30fd/#314 broke it

kallestenflo added a commit that referenced this issue Jun 29, 2017
fix evaluation of `empty` with wrapping providers (fixes #366)
@trustin
Copy link
Author

trustin commented Jun 30, 2017

Thanks a lot for a super quick fix! Any chance of cutting a new release?

@trustin trustin changed the title Regression in a nested query Regression in JacksonJsonNodeJsonProvider Jun 30, 2017
cmunilla pushed a commit to cmunilla/JPath that referenced this issue Oct 30, 2017
cmunilla pushed a commit to cmunilla/JPath that referenced this issue Oct 30, 2017
fix evaluation of `empty` with wrapping providers (fixes json-path#366)
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

2 participants