[PR #155] [CLOSED] Replace JsonMatcher with JsonObjectMatcher and directly support JSON body matching. #779

Closed
opened 2025-12-29 15:33:11 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/wiremock/WireMock.Net/pull/155
Author: @DavidKorn
Created: 6/26/2018
Status: Closed

Base: masterHead: dk_154_request_bodyasjson


📝 Commits (1)

  • a6910c5 Replace the just added JsonMatcher with JsonObjectMatcher, which uses value equality via JSON serialization to support JSON object matches in request bodies. Update the proxy recorder to use JsonObjectMatcher to record the mapping for a Request with a BodyAsJson. #154

📊 Changes

9 files changed (+144 additions, -122 deletions)

View changed files

📝 examples/WireMock.Net.ConsoleApplication/MainApp.cs (+1 -1)
📝 src/WireMock.Net/Admin/Mappings/MatcherModel.cs (+2 -2)
📝 src/WireMock.Net/Matchers/IValueMatcher.cs (+1 -1)
📝 src/WireMock.Net/Matchers/JsonObjectMatcher.cs (+14 -11)
📝 src/WireMock.Net/Serialization/MatcherMapper.cs (+6 -5)
📝 src/WireMock.Net/Server/FluentMockServer.Admin.cs (+6 -2)
test/WireMock.Net.Tests/Matchers/JsonMatcherTests.cs (+0 -100)
test/WireMock.Net.Tests/Matchers/JsonObjectMatcherTests.cs (+91 -0)
📝 test/WireMock.Net.Tests/RequestMatchers/RequestMessageBodyMatcherTests.cs (+23 -0)

📄 Description

JsonObjectMatcher uses value equality via JSON serialization to support JSON object matches in request bodies. This allows static mapping files to code JSON bodies as indented JSON syntax directly in the mapping file. For our use, that's much easier to work with than an escaped string.

Also update the proxy recorder to use JsonObjectMatcher to record the mapping for a Request with a BodyAsJson.

Note: I didn't initially intend to remove the just added JsonMatcher, and I apologize if that offends. I was trying to figure out how to work alongside it and support a JsonObjectMatcher, and things got a bit messy for me around the IValueMatcher interface. In the end, with this JsonObjectMatcher class in place, and the existing IStringMatchers already available, the JsonMatcher seemed to me to be mostly redundant. So I didn't work to re-include it, but I'll be glad to try to do so if you prefer.

#154


🔄 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/155 **Author:** [@DavidKorn](https://github.com/DavidKorn) **Created:** 6/26/2018 **Status:** ❌ Closed **Base:** `master` ← **Head:** `dk_154_request_bodyasjson` --- ### 📝 Commits (1) - [`a6910c5`](https://github.com/wiremock/WireMock.Net/commit/a6910c556266439c18afced5387bb645c2ff725c) Replace the just added JsonMatcher with JsonObjectMatcher, which uses value equality via JSON serialization to support JSON object matches in request bodies. Update the proxy recorder to use JsonObjectMatcher to record the mapping for a Request with a BodyAsJson. #154 ### 📊 Changes **9 files changed** (+144 additions, -122 deletions) <details> <summary>View changed files</summary> 📝 `examples/WireMock.Net.ConsoleApplication/MainApp.cs` (+1 -1) 📝 `src/WireMock.Net/Admin/Mappings/MatcherModel.cs` (+2 -2) 📝 `src/WireMock.Net/Matchers/IValueMatcher.cs` (+1 -1) 📝 `src/WireMock.Net/Matchers/JsonObjectMatcher.cs` (+14 -11) 📝 `src/WireMock.Net/Serialization/MatcherMapper.cs` (+6 -5) 📝 `src/WireMock.Net/Server/FluentMockServer.Admin.cs` (+6 -2) ➖ `test/WireMock.Net.Tests/Matchers/JsonMatcherTests.cs` (+0 -100) ➕ `test/WireMock.Net.Tests/Matchers/JsonObjectMatcherTests.cs` (+91 -0) 📝 `test/WireMock.Net.Tests/RequestMatchers/RequestMessageBodyMatcherTests.cs` (+23 -0) </details> ### 📄 Description JsonObjectMatcher uses value equality via JSON serialization to support JSON object matches in request bodies. This allows static mapping files to code JSON bodies as indented JSON syntax directly in the mapping file. For our use, that's much easier to work with than an escaped string. Also update the proxy recorder to use JsonObjectMatcher to record the mapping for a Request with a BodyAsJson. Note: I didn't initially intend to remove the just added JsonMatcher, and I apologize if that offends. I was trying to figure out how to work alongside it and support a JsonObjectMatcher, and things got a bit messy for me around the IValueMatcher interface. In the end, with this JsonObjectMatcher class in place, and the existing IStringMatchers already available, the JsonMatcher seemed to me to be mostly redundant. So I didn't work to re-include it, but I'll be glad to try to do so if you prefer. #154 --- <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 15:33:11 +01:00
adam closed this issue 2025-12-29 15:33:11 +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-wiremock#779