Hi friends I'm new to WireMock and facing a issu, ...
# help
r
Hi friends I'm new to WireMock and facing a issu, which I doesn't understand. I'm using wiremock-jre8-standalone-2.31.0 and try to use the placeholders for the
equalToJson
. In fact I've a date as property, which is created with LocalDateTime.now(). And clearly this date will never match. So here is my jsonRequestBody
Copy code
String jsonRequestBody = String.format("{ \"document\": {\"documentData\": \"%s\"}, \"documentMetadata\": {\"documentId\": \"MYA-1234\", \"docType\": \"LEA\", \"docDataType\": \"PDF\", \"docName\": \"Some pdf\", \"insuredId\": 2000001, \"partnerId\": null, \"familyId\": 1000001, \"offerId\": null, \"contractId\": null, \"receiptId\": null, \"statementOfBenfitsId\": null, \"dasId\": null, \"zsrId\": null, \"enforcementId\": null, \"vipCode\": null, \"dossierId\": null, \"debitorId\": null, \"taskId\": null, \"tessiImageId\": null, \"invoiceId\": null, \"creationDate\": \"%s\", \"changeDate\": null, \"startDateRetentionPeriod\": null, \"insuranceType\": null, \"overdueReminderType\": null, \"receiptType\" : null, \"tessiType\" : null}}", document.getContent(), "${json-unit.ignore}");
As u can see, for the creationDate I'm trying to use a placeholder, like it's described here: https://wiremock.org/docs/request-matching/ But it doesn't work. Any idea why? Thank you in advance
a
Have you tried
json-unit.any-string
?
r
Yes I did. Unfortunately it's the same result
a
Do you need to match on the entire request body, or is there a certain key:value?
r
No there are many `null`values which I could skip. There are more or less five params, which I'm interested in
a
So, you could make use of the
ignoreExtraElements
flag to just check for those attributes. For example:
Copy code
// actual request body
{
  "foo": "bar",
  "baz": "bar"
}
Copy code
...
.withRequestBody(equalToJson("{ \"foo\": \"bar\" }", true, true))
...
Would match, even though I haven’t provided a match for
"baz"
r
o.k. I will give it a try, thank you