json-path / JsonPath

Java JsonPath implementation
Apache License 2.0
8.85k stars 1.63k forks source link

Cache for concat method fails #491

Open ghost opened 6 years ago

ghost commented 6 years ago

Hello,

My issue is related to the issue #234. It is working with the issue's example, but if I use the concat method on two different objet (there, the context input was the same for both call for the method), the cache will give me the first answer for the second call :

Map<String, String> context1 = Maps.newHashMap();
context1.put("key", "first");
Object value = JsonPath.read(context1, "concat(\"/\", $.key)");
assertThat(value).isEqualTo("/first");

Map<String, String> context2 = Maps.newHashMap();
context2.put("key", "second");
value = JsonPath.read(context2, "concat(\"/\", $.key)");
assertThat(value).isEqualTo("/second"); //fail, return "first"

Thank you

mborgraeve commented 3 years ago

I'm experiencing the same behavior with 2.4.0. How can I help to resolve this ?

For more detail, you can have a look at my test there: https://github.com/mborgraeve/json-path-cache-concat-issue Class here: https://github.com/mborgraeve/json-path-cache-concat-issue/blob/main/src/test/java/mborgraeve/samples/jsonpathcacheconcat/JsonPathCacheConcatApplicationTests.java

I tried to run JsonPath.read(jsonPathObject, "concat($.intervalMeasure.['date', 'time'])", new Predicate[0]); with two different jsonPathObject (that are actually LinkedHashMaps). I expect two different result, but the method returns the same result each time.

It looks like the same as #234.

deroffal commented 3 years ago

Hi @mborgraeve ,

From what I remember about the issue after 2 years, you can try to disable the global cache to prevent this :

CacheProvider.setCache(new NOOPCache());

I hope it will help !

mborgraeve commented 3 years ago

It does work with this configuration, thanks a lot !