Loading mapping models with `JsonMatcher` is not working correctly
See original GitHub issueDescribe the bug
Loading mapping models with JsonMatcher
for Body matcher from a file is not working correctly.
Steps to reproduce:
- 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);
- 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"
}
}
}
- 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
This is how requestBuilder
looks like after loading from a file
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:
- Created 3 years ago
- Comments:19
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
@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.