ignoring null values when matching json request

1,323 views
Skip to first unread message

Vipin Jose

unread,
Jan 8, 2018, 5:16:14 PM1/8/18
to wiremock-user
Hi Tom, Team

Is there a way to ignore properties with null values in when matching null request?

2018-01-08 17:05:47.539 [qtp409598930-57] ERROR WireMock - 
                                               Request was not matched
                                               =======================

-----------------------------------------------------------------------------------------------------------------------
| Closest stub                                             | Request                                                  |
-----------------------------------------------------------------------------------------------------------------------
                                                           |
POST                                                 | POST
/person/                                              | /person/
                                                           |
{                                                          | {                                                   <<<<< Body does not match
  "name" : {                                         |   "name" : {
    "family-name" : "Smith",                 |     "family-name" : "Smith"
    "given-name" : null                         |   }
  }                                                        | }
}                                                          |
                                                           |
-----------------------------------------------------------------------------------------------------------------------

Regards,
Vipin

Tom Akehurst

unread,
Jan 9, 2018, 6:13:08 AM1/9/18
to wiremock-user
I suggest removing the given-name field entirely from your stub, and switching to loose JSON matching i.e.

equalToJson("{ ...  }", true, true)

or in JSON:

{
      "equalToJson" : "{ ...  }",
      "ignoreArrayOrder" : true,
      "ignoreExtraElements" : true
}

This will match the JSON on the right in your example, and will also match if given-name is present.

cukes...@gmail.com

unread,
Mar 8, 2018, 4:33:09 AM3/8/18
to wiremock-user
Hi,

I have the same issue here. But what I need is that if given-name does have a value rather than null, it would fail the matching.

equalToJson("{ ...  }", true, true) does not fail the matching if given-name has a value.

Do you know how to solve this issue?

Thank you very much for your reply in advance.
Reply all
Reply to author
Forward
0 new messages