mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 22:30:41 +01:00
JsonPathMatcher does not match json body nested objects #524
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @timurnes on GitHub (Jul 10, 2023).
Originally assigned to: @StefH on GitHub.
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" } ] }@StefH commented on GitHub (Jul 12, 2023):
https://github.com/WireMock-Net/WireMock.Net/pull/966
@StefH commented on GitHub (Jul 12, 2023):
@timurnes
You can check version
1.5.31-ci-17598https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions
@timurnes commented on GitHub (Jul 13, 2023):
@StefH
Thanks,
1.5.31-ci-17598works correctly. Waiting for release package version :)Update: It doesn't. Please take a look on my next comment
@timurnes commented on GitHub (Jul 13, 2023):
@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:
@StefH commented on GitHub (Jul 13, 2023):
@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:
@timurnes commented on GitHub (Jul 13, 2023):
@StefH
Sure, I used JsonPartialMatcher when I discovered that JsonPathMatcher does not work correctly - it looks better for my case
@StefH commented on GitHub (Jul 15, 2023):
@timurnes
Making the fix recursive is not that easy, so for now I'll merge this PR as-is.