Closed timurnes closed 12 months ago
@timurnes
You can check version
1.5.31-ci-17598
https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions
@StefH
Thanks, 1.5.31-ci-17598
works correctly. Waiting for release package version :)
Update: It doesn't. Please take a look on my next comment
@StefH The fix is working only with first-level nested objects. It seems that the root cause is deeper (looking on your commits - Newtonsoft.Json?). This test fails:
[Fact]
public void JsonPathMatcher_IsMatch_JsonStringWithNestedObjects()
{
// Assign
var json = "{ \"things\": { \"nested\": { \"name\": \"RequiredThing\" } } }";
var matcher = new JsonPathMatcher("$.things.nested[?(@.name == 'RequiredThing')]");
// Act
double match = matcher.IsMatch(json);
// Assert
Check.That(match).IsEqualTo(1);
}
@timurnes You are correct. My fix is just a workaround for the first level. To make it work for all levels, I need to call the code recursive. I'll check this.
BTW you know that you also can use a https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching#dynamic-linq-linqmatcher
Which is much easier to use:
"things.nested.name == \"RequiredThing\""
@StefH Sure, I used JsonPartialMatcher when I discovered that JsonPathMatcher does not work correctly - it looks better for my case
@timurnes Making the fix recursive is not that easy, so for now I'll merge this PR as-is.
Describe the bug
JsonPathMatcher example in official documentation does not match json body with nested fields: Pattern:
$.things[?(@.name == 'RequiredThing')]
Json:{ "things": { "name": "RequiredThing" } }
First-level fields match works correctly
Expected behavior:
JsonPathMatcher correctly matches json body with nested fields
Test to reproduce
Other related info
The same pattern works correctly with another json from example:
{ "things": [ { "name": "RequiredThing" }, { "name": "Wiremock" } ] }