与 CustomComparator 比较时忽略 jsonassert 中的特定属性/字段
温馨提示:
本文最后更新于 2024年04月12日,已超过 48 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我。
I need to compare two json strings but ignore some fields ("changeDate")
JSON 1
{
"listInfo": {
"offset": 0,
"limit": 20,
"count": 1
},
"items": [
{
"tsetId": 3,
"name": "Bonus test",
"description": "Bonus test description",
"changeDate": "2024-04-09T09:14:27.899775",
"changeUser": "user",
"isDefault": false
}
]
}
JSON 2
{
"listInfo": {
"offset": 0,
"limit": 20,
"count": 1
},
"items": [
{
"tsetId": 3,
"name": "Bonus test",
"description": "Bonus test description",
"changeDate": "2024-03-03T04:44:17.1569775",
"changeUser": "user",
"isDefault": false
}
]
}
I use JSONAssert and CustomComparator like this
JSONAssert.assertEquals(expectedResponseBody, actualResponseBody, //JSONCompareMode.LENIENT);
new CustomComparator(JSONCompareMode.LENIENT, new Customization("**.changeDate", (o1, o2) -> true)
));
and I get an error
java.lang.AssertionError: items[changeDate=2024-04-09T09:14:27.899775]
Expected: a JSON object
but none found
; items[changeDate=2024-03-03T04:44:17.1569775]
Unexpected: a JSON object
I tried to use "items.changeDate"
, "items[0].changeDate"
, "items[*].changeDate"
in path in Customization and got the same error.
What is the right path in my case? Or may be the problem is somewhere else...
正文到此结束
- 本文标签: 家庭宠物
- 本文链接: https://www.coder6.net/article/2414
- 版权声明: 本文由蚂蚁原创发布,转载请遵循《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权
热门推荐
-
浏览(193) 评论(0)