question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Loading mapping models with `JsonMatcher` is not working correctly

See original GitHub issue

Describe the bug

Loading mapping models with JsonMatcher for Body matcher from a file is not working correctly.

Steps to reproduce:

  1. Create mapping with JsonMatcher for the body and save it to file as follow
var requestBuilder = Request.Create()
	.WithPath("/api/v1.0/accounts/")
	.WithHeader("Content-Type", "application/json; charset=utf-8")
	.WithBody(new JsonMatcher(new { AccountIds = new[] { 1, 2, 3} }))
	.UsingPost();

var respondWithAProvider = wiremockServer.Given(requestBuilder, saveToFile: true);

var responseProvider = Response.Create()
	.WithStatusCode(200)
	.WithHeader("Content-Type", "application/json; charset=utf-8")
	.WithBody(JsonConvert.SerializeObject(new[] { 1, 2, 3 }));

wiremockServer.RespondWith(responseProvider);
  1. As a result I get a file with the following content
{
  "Guid": "7d1c7dcc-eba1-4c3a-bc82-0a444fe9fcd9",
  "Request": {
    "Path": {
      "Matchers": [
        {
          "Name": "WildcardMatcher",
          "Pattern": "/api/v1.0/accounts/",
          "IgnoreCase": false
        }
      ]
    },
    "Methods": [
      "POST"
    ],
    "Headers": [
      {
        "Name": "Content-Type",
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "application/json; charset=utf-8",
            "IgnoreCase": true
          }
        ]
      }
    ],
    "Body": {
      "Matcher": {
        "Name": "JsonMatcher",
        "Pattern": {
          "AccountIds": [1, 2, 3]
        },
        "IgnoreCase": false
      }
    }
  },
  "Response": {
    "StatusCode": 200,
    "BodyDestination": "SameAsSource",
    "Body": "[1,2,3]",
    "Headers": {
      "Content-Type": "application/json; charset=utf-8"
    }
  }
}
  1. Load mapping from file and feed it to the WireMock server
var content = File.ReadAllText(@"__admin\mappings\7d1c7dcc-eba1-4c3a-bc82-0a444fe9fcd9.json");
wiremockServer.WithMapping(content);

Expected behavior:

This is how requestBuilder looks like before saving mapping to a file image

This is how requestBuilder looks like after loading from a file

image

The expectation is that the JsonMatcher works in the same way when loaded from a file and when created from the code. Currently, the pattern is always set to null when loading from a file.

Other notes

This is probably caused by this line where every pattern is cast to string (non-string values will result with a null) https://github.com/WireMock-Net/WireMock.Net/blob/7abf56eafaf9d57aff1234bf7c0ad0f408bb18d6/src/WireMock.Net/Serialization/MatcherMapper.cs#L39

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:19

github_iconTop GitHub Comments

1reaction
StefHcommented, Oct 14, 2020

Hello @RiccoFerraro , I’ll release a new version with this fix tonight and for now close this issue.

In case you have another problem please create a new issue.

1reaction
StefHcommented, Oct 12, 2020

@RiccoFerraro Thanks about your remark about the Http VERB. I did create a new Issue for this, and I’ll take a look how to fix this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Warning: Problem loading the .json data file for mapping
Open a new tab in your Chrome browser and click on the round picture or initial in the top-right corner. You will be...
Read more >
Spring JPA JSON to model mapping doesnt ...
I defined a table in my PostgreSQL with the following schema: CREATE TABLE public.customer ( id integer NOT NULL, firstname character varying ...
Read more >
Loading JSON with missing properties in mapping plugin
I'm loading a JSON array that represents records in a database from a REST endpoint. When a record's field has no value, it's...
Read more >
Texture not showing right with custom model : r/Blockbench
I made a custom .json model (it's supposed to be a flag on a pole) and the texture is not showing right, given...
Read more >
All Classes (Atlassian Confluence 8.2.0-m27 API)
Loads a map of macro metadata by macro names when given a macro module descriptor ... Flags API Model classes that represent enums,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found