[PR #539] [MERGED] Support for partial JSON matching #958

Closed
opened 2025-12-29 08:34:08 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/wiremock/WireMock.Net/pull/539
Author: @gleb-osokin
Created: 11/16/2020
Status: Merged
Merged: 11/17/2020
Merged by: @StefH

Base: masterHead: master


📝 Commits (10+)

  • 91e3e9c support Json partial match with JsonPartialMatcher
  • f7edfa0 fix erroneous filenames
  • d3838d6 add newline
  • b0efe08 newlines fix
  • 4af601e add JsonPartialMatcher to mapper
  • 9378d4d curly braces for ifs
  • 1c109bd fix JToken type comparison
  • 099368e more test cases
  • a08318b rename AreEqual -> IsMatch + more test cases
  • 4a2adb9 separate tests for JPath matcher values

📊 Changes

5 files changed (+578 additions, -17 deletions)

View changed files

📝 src/WireMock.Net/Matchers/JsonMatcher.cs (+21 -16)
src/WireMock.Net/Matchers/JsonPartialMatcher.cs (+87 -0)
📝 src/WireMock.Net/Serialization/MatcherMapper.cs (+4 -0)
test/WireMock.Net.Tests/Matchers/JsonPartialMatcherTests.cs (+385 -0)
📝 test/WireMock.Net.Tests/Serialization/MatcherMapperTests.cs (+81 -1)

📄 Description

Current JsonMatcher only support exact match (via JToken.DeepEquals).
This PR introduces new JsonPartialMatcher, which tolerates input properties, not existing on the Matcher value.

Example:
Matcher value {"test": "abc"} against input {"test":"abc"} is matched by both JsonMatcher and JsonPartialMatcher
Matcher value {"test":"abc"} against input {"test":"abc","other":"xyz"} is not matched by JsonMatcher, but is matched by JsonPartialMatcher

One side benefit of this PR is that JsonMatcher (and JsonPartialMatcher) are now extensible via virtual AreEqual(JToken, JToken) method.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/wiremock/WireMock.Net/pull/539 **Author:** [@gleb-osokin](https://github.com/gleb-osokin) **Created:** 11/16/2020 **Status:** ✅ Merged **Merged:** 11/17/2020 **Merged by:** [@StefH](https://github.com/StefH) **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (10+) - [`91e3e9c`](https://github.com/wiremock/WireMock.Net/commit/91e3e9c0e9fd925a65816505bb6c83ae689119e2) support Json partial match with JsonPartialMatcher - [`f7edfa0`](https://github.com/wiremock/WireMock.Net/commit/f7edfa01ddf371af2417b42746bd0e03f71082c2) fix erroneous filenames - [`d3838d6`](https://github.com/wiremock/WireMock.Net/commit/d3838d66099d8f6c4e5115814c55313a59177aeb) add newline - [`b0efe08`](https://github.com/wiremock/WireMock.Net/commit/b0efe080fa86582c6716d5e91f12f30ac93e0869) newlines fix - [`4af601e`](https://github.com/wiremock/WireMock.Net/commit/4af601e17b48af387f1ad47f12dd7e359e28e947) add JsonPartialMatcher to mapper - [`9378d4d`](https://github.com/wiremock/WireMock.Net/commit/9378d4d8a5113b78650551bcfe9d24f13ca633b1) curly braces for ifs - [`1c109bd`](https://github.com/wiremock/WireMock.Net/commit/1c109bd0e0b56eaf86645e9d354949440cdb0e59) fix JToken type comparison - [`099368e`](https://github.com/wiremock/WireMock.Net/commit/099368e0f9db2e9a8a03dba565e4c49e52707ab0) more test cases - [`a08318b`](https://github.com/wiremock/WireMock.Net/commit/a08318bc57977a546d6d015457c144180727d926) rename AreEqual -> IsMatch + more test cases - [`4a2adb9`](https://github.com/wiremock/WireMock.Net/commit/4a2adb9a9998366c55b41922d225efdc57c9044d) separate tests for JPath matcher values ### 📊 Changes **5 files changed** (+578 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `src/WireMock.Net/Matchers/JsonMatcher.cs` (+21 -16) ➕ `src/WireMock.Net/Matchers/JsonPartialMatcher.cs` (+87 -0) 📝 `src/WireMock.Net/Serialization/MatcherMapper.cs` (+4 -0) ➕ `test/WireMock.Net.Tests/Matchers/JsonPartialMatcherTests.cs` (+385 -0) 📝 `test/WireMock.Net.Tests/Serialization/MatcherMapperTests.cs` (+81 -1) </details> ### 📄 Description Current JsonMatcher only support exact match (via JToken.DeepEquals). This PR introduces new JsonPartialMatcher, which tolerates input properties, not existing on the Matcher value. Example: Matcher value **{"test": "abc"}** against input **{"test":"abc"}** is matched by both JsonMatcher and JsonPartialMatcher Matcher value **{"test":"abc"}** against input **{"test":"abc","other":"xyz"}** is not matched by JsonMatcher, but is matched by JsonPartialMatcher One side benefit of this PR is that JsonMatcher (and JsonPartialMatcher) are now extensible via virtual AreEqual(JToken, JToken) method. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 08:34:08 +01:00
adam closed this issue 2025-12-29 08:34:08 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#958