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.

JsonMatcher not working when JSON contains a DateTimeOffset

See original GitHub issue

Hi, I’m trying to match wiremock match on the body of an incoming POST, and am having trouble with DateTimeOffsets.

If we start with the example from the wiki: https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching#json-jsonmatcher everything works as expected. A request to /jsonmatcher1 with the body:

{
	x: 42,
	s: "s"
}

works as expected and gives the response.

When I delete that mapping and add a new one with a DateTimeOffset property in the body:

{
    "Guid": "debaf408-3b23-4c04-9d18-ef1c020e79f2",
    "Request": {
        "Path": {
            "Matchers": [
                {
                    "Name": "WildcardMatcher",
                    "Pattern": "/jsonmatcher1"
                }
            ]
        },
        "Methods": [
            "post"
        ],
        "Body": {
            "Matcher": {
                "Name": "JsonMatcher",
                "Pattern": "{ \"x\": 42, \"s\": \"s\", \"preferredAt\": \"2019-11-21T10:32:53.2210009+00:00\" }"
            }
        }
    },
    "Response": {
        "StatusCode": 200,
        "Body": "{ \"result\": \"jsonbodytest\" }",
        "UseTransformer": false
    }
}

and send the same request as before, but now with body:

{
	x: 42,
	s: "s",
	preferredAt: "2019-11-21T10:32:53.2210009+00:00"
}

it doesn’t work (returns {"Status": "No matching mapping found"}).

I assume wiremock.net is doing some special processing on these DateTimeOffset values and it isn’t working in this case, or am I doing something wrong? Also: Is there any way of making wiremock.net treat these as strings and just compare them as strings? For my current use-case that would suffice. Cheers, Josh

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12

github_iconTop GitHub Comments

1reaction
StefHcommented, Oct 9, 2019

“Build StandAlone.NETCoreApp” is probably there to quickly check if the code can build.

Cool that it works, I will close this issue and a new official NuGet + docker will be released in few days. Just keep watching this project or dockerhub.

1reaction
StefHcommented, Oct 8, 2019

This looks a lot like https://github.com/WireMock-Net/WireMock.Net/issues/347

I’ll investigate the JsonMatcher code…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is Newtonsoft.Json failing to parse a DateTimeOffset ...
1 Answer. You don't have valid JSON. You have some kind of embedding going on, and it contains quotes around an incorrectly escaped...
Read more >
Using JSONMatch
A JSONMatch path is an expression that, when evaluated, resolves to one or more locations in JSON document. A path can traverse object...
Read more >
Work with JSON data in SQL Server
JSON functions, first introduced in SQL Server 2016 (13.x), enable you to combine NoSQL and relational concepts in the same database. Now you ......
Read more >
Getting Started: Entity Framework Core 7 JSON Support
This post will discuss the advantages of using JSON when data modeling, the benefits of storing JSON, and how to work with JSON...
Read more >
Unity Json utility does not serialize DateTime
The problem with JsonUtility, is that it doesn't save properties, just public fields and fields with the [SerializeField] attribute.
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