我已经请求JSON body
[
{"name" : "Ram"},
{"name" : "Sam"}
]
这是我需要匹配请求的wiremock请求的输入,即使JSON具有相同的内容但值可能不是相同的顺序。例如,
[
{"name" : "Sam"},
{"name" : "Ram"}
]
我使用的方法是.withRequestBody. I tried with
equalToJson`但不起作用。什么是匹配仅检查JSON内容而不是订单的匹配器?
这可以使用JsonPath解决,JsonPath是bodyPatterns相等匹配功能的一部分。
{
"request" : {
"urlPathPattern" : "/jpath/.*",
"method" : "GET",
"bodyPatterns" : [ {
"matchesJsonPath" : "$[?(@.name == 'Sam')]"
} ]
},
"response" : {
"status" : 200,
"body" : "Works"
}
}
使用JsonPath online evaluator可以轻松测试JsonPath表达式。有关可能的更多详细信息,请查看here。