How to match number with JsonPartialWildcardMatcher #403

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

Originally created by @robertmircea on GitHub (Feb 13, 2022).

I have the following body matcher in json mapping file and I would like to match any number for price field.

    "Body": {
      "Matcher": {
        "Name": "JsonPartialWildcardMatcher",
        "Pattern": {
          "applicationId": "*",
          "currency": "EUR",
          "price": *,
          "externalId": "*",
          "transactionDescription": "*",
        },
        "IgnoreCase": false
      }
    }

The file loading crashes with File xyz.json could not be read. This file will be skipped. probably because it is not a valid json file. If I specify:

"price": "*"

no matching happens (No matching mapping found). Using AllowPartialMapping=false

Originally created by @robertmircea on GitHub (Feb 13, 2022). I have the following body matcher in json mapping file and I would like to match any number for `price` field. ```json "Body": { "Matcher": { "Name": "JsonPartialWildcardMatcher", "Pattern": { "applicationId": "*", "currency": "EUR", "price": *, "externalId": "*", "transactionDescription": "*", }, "IgnoreCase": false } } ``` The file loading crashes with `File xyz.json could not be read. This file will be skipped.` probably because it is not a valid json file. If I specify: ```json "price": "*" ``` no matching happens (`No matching mapping found`). Using `AllowPartialMapping=false`
adam added the question label 2025-12-29 08:27:29 +01:00
adam closed this issue 2025-12-29 08:27:29 +01:00
Author
Owner

@StefH commented on GitHub (Feb 14, 2022):

@robertmircea
No sorry.

This matcher can only match (at least for now) on string-values. I don't know yet how to implement this logic.

In the meantime, you could try to use the csharp-code-csharpcodematcher

@StefH commented on GitHub (Feb 14, 2022): @robertmircea No sorry. This matcher can only match (at least for now) on string-values. I don't know yet how to implement this logic. In the meantime, you could try to use the [csharp-code-csharpcodematcher](https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching#csharp-code-csharpcodematcher)
Author
Owner

@StefH commented on GitHub (Jul 11, 2022):

@robertmircea
I can fix this by allowing a regular expression:

So in your case:

    "Body": {
      "Matcher": {
        "Name": "JsonPartialWildcardMatcher",
        "Regex": true, // <--- add this property
        "Pattern": {
          "applicationId": "*",
          "currency": "EUR",
          "price": "^\\d*$", // <--- use regex
          "externalId": "*",
          "transactionDescription": "*",
        },
        "IgnoreCase": false
      }
    }
@StefH commented on GitHub (Jul 11, 2022): @robertmircea I can fix this by allowing a regular expression: So in your case: ``` js "Body": { "Matcher": { "Name": "JsonPartialWildcardMatcher", "Regex": true, // <--- add this property "Pattern": { "applicationId": "*", "currency": "EUR", "price": "^\\d*$", // <--- use regex "externalId": "*", "transactionDescription": "*", }, "IgnoreCase": false } } ```
Author
Owner

@StefH commented on GitHub (Jul 11, 2022):

@robertmircea
You can try preview version 1.5.1-ci-16292 (https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions)

@StefH commented on GitHub (Jul 11, 2022): @robertmircea You can try preview version `1.5.1-ci-16292` (https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions)
Author
Owner

@StefH commented on GitHub (Jul 11, 2022):

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

@StefH commented on GitHub (Jul 11, 2022): https://github.com/WireMock-Net/WireMock.Net/pull/771
Author
Owner

@StefH commented on GitHub (Jul 13, 2022):

@robertmircea : did you have time to test?

@StefH commented on GitHub (Jul 13, 2022): @robertmircea : did you have time to test?
Author
Owner

@StefH commented on GitHub (Jul 18, 2022):

@robertmircea : Can you please test that preview version to see if this works for you?

@StefH commented on GitHub (Jul 18, 2022): @robertmircea : Can you please test that preview version to see if this works for you?
Author
Owner

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

Merged to main and a new version is released to NuGet.

@StefH commented on GitHub (Jul 24, 2022): Merged to main and a new version is released to NuGet.
Author
Owner

@robertmircea commented on GitHub (Aug 3, 2022):

For me, I confirm that this release allows me to match numbers using regex expression. Thank you for support.

@robertmircea commented on GitHub (Aug 3, 2022): For me, I confirm that this release allows me to match numbers using regex expression. Thank you for support.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#403