Record request mapping outputs JsonMatcher with Patterns instead of Pattern #397

Closed
opened 2025-12-29 08:27:24 +01:00 by adam · 5 comments
Owner

Originally created by @tjpeel on GitHub (Jan 24, 2022).

Originally assigned to: @StefH on GitHub.

Hi,

I collated the following example https://github.com/tjpeel/wiremock-question-jsonmatcher/blob/main/Program.cs#L23-L46

Please run the Program to see the issue.

The issue might be a misconfiguration on my part or be by design, or be a bug, which is why the example was made.

TLDR; when a request is recorded with a request body, the mapping includes a JsonMatcher with a Patterns property, yet when the mapping is used it will never match the request again as the incoming request is checked against an array (Patterns property) instead of each item in the array. Or it should have serialised the recorded request using the Pattern property instead.

Example servers from Program.cs

  1. A wiremock instance representing a downstream service
  2. A wiremock instance that proxies to the downstream service and records mappings
  3. A wiremock instance that uses a pre-recorded mapping (jsonpatterns)
  • The request body JsonMatcher is as was recorded via the proxying server (2) above
  • The Patterns property of the JsonMatcher is an array, which then contains the request body that was recorded
  • There have been no manual changes to this file, it's what was recorded
  • When the same request is processed by this server, it cannot match as it compares an array of request body values to a single request body; so this results in a 404
  1. A wiremock instance that uses an adapted pre-recorded mapping (jsonpattern)
  • The request body JsonMatcher was changed manually from Patterns -> Pattern
  • The Pattern property is the request payload and not an array
  • When the same request is processed by this server, it can match and return the response

Many thanks

Originally created by @tjpeel on GitHub (Jan 24, 2022). Originally assigned to: @StefH on GitHub. Hi, I collated the following example https://github.com/tjpeel/wiremock-question-jsonmatcher/blob/main/Program.cs#L23-L46 Please run the Program to see the issue. The issue might be a misconfiguration on my part or be by design, or be a bug, which is why the example was made. **_TLDR; when a request is recorded with a request body, the mapping includes a JsonMatcher with a Patterns property, yet when the mapping is used it will never match the request again as the incoming request is checked against an array (Patterns property) instead of each item in the array. Or it should have serialised the recorded request using the Pattern property instead._** Example servers from [Program.cs](https://github.com/tjpeel/wiremock-question-jsonmatcher/blob/main/Program.cs) 1. A wiremock instance representing a downstream service 2. A wiremock instance that proxies to the downstream service and records mappings 3. A wiremock instance that uses a pre-recorded mapping (jsonpatterns) - The request body JsonMatcher is as was recorded via the proxying server (2) above - The Patterns property of the JsonMatcher is an array, which then contains the request body that was recorded - There have been no manual changes to this file, it's what was recorded - When the same request is processed by this server, it cannot match as it compares an array of request body values to a single request body; so this results in a 404 4. A wiremock instance that uses an adapted pre-recorded mapping (jsonpattern) - The request body JsonMatcher was changed manually from Patterns -> Pattern - The Pattern property is the request payload and not an array - When the same request is processed by this server, it can match and return the response Many thanks
adam added the bug label 2025-12-29 08:27:24 +01:00
adam closed this issue 2025-12-29 08:27:24 +01:00
Author
Owner

@StefH commented on GitHub (Jan 24, 2022):

@tjpeel
Thank you for this issue with extended description.

I think I found some issues in the JsonMatcher, this cannot handle Patterns (yet).

For now I'll just change the Save code to output pattern instead of patterns`.

Can you try preview version 1.4.33-ci-15809 ?
https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions

@StefH commented on GitHub (Jan 24, 2022): @tjpeel Thank you for this issue with extended description. I think I found some issues in the JsonMatcher, this cannot handle `Patterns` (yet). For now I'll just change the **Save** code to output `pattern` instead of patterns`. Can you try preview version 1.4.33-ci-15809 ? https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions
Author
Owner

@tjpeel commented on GitHub (Jan 24, 2022):

Thanks, sounds good. I’ll give it a try in the morning but I’m sure all will be good if it defaults to save as Pattern 👍

@tjpeel commented on GitHub (Jan 24, 2022): Thanks, sounds good. I’ll give it a try in the morning but I’m sure all will be good if it defaults to save as Pattern 👍
Author
Owner

@StefH commented on GitHub (Jan 27, 2022):

@tjpeel
Did you have time to verify ?

@StefH commented on GitHub (Jan 27, 2022): @tjpeel Did you have time to verify ?
Author
Owner

@tjpeel commented on GitHub (Jan 27, 2022):

Please forgive me @StefH I was offline for the past couple of days. I have just checked now and all looks good. Thanks!

@tjpeel commented on GitHub (Jan 27, 2022): Please forgive me @StefH I was offline for the past couple of days. I have just checked now and all looks good. Thanks!
Author
Owner

@StefH commented on GitHub (Jan 27, 2022):

Hello @tjpeel, thanks for testing.

A new official NuGet version will be released shorty.

https://github.com/WireMock-Net/WireMock.Net/pull/716

@StefH commented on GitHub (Jan 27, 2022): Hello @tjpeel, thanks for testing. A new official NuGet version will be released shorty. https://github.com/WireMock-Net/WireMock.Net/pull/716
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#397