java - 比较两个 json 文件时忽略特定属性
问题描述
我已经成功地使用 JSONAssert 来比较两个这样的 json 响应:
JSONAssert.assertEquals(response2.getResponseBodyContent(), response1.getResponseBodyContent(), JSONCompareMode.LENIENT)
我现在需要忽略此处描述的某些属性:
在比较两个 JSON 时忽略特定节点/属性 我的新声明是:
JSONAssert.assertEquals(response2, getResponseBodyContent(), new CustomComparator(JSONCompareMode.LENIENT, new Customization("EffectiveEpochDate", (o1, o2) -> true)));
我收到以下错误:
java.lang.Error: Unresolved compilation problems:
Groovy:expecting ')', found ',' @ line 51, column 154.
Groovy:expecting ')', found '->' @ line 51, column 160.
Groovy:expecting ')', found '->' @ line 51, column 160.
Groovy:expecting '}', found '->' @ line 51, column 160.
Groovy:expecting '}', found '->' @ line 51, column 160.
我正在使用一个名为 Katalon 的测试工具,它支持 java/groovy。任何输入将不胜感激。谢谢
解决方案
The code you are referencing uses the Java lambda syntax (which for sure is not supported up to and including Groovy 2.5). You have to pass an closure instead. E.g. turn
(o1, o2) -> true
into:
{a, b -> true}
推荐阅读
- r - 用 Excel 编写的日期格式一般不是日期
- vim - 如何创建能够识别具有不同语法的多个部分的集中语法文件?
- java - 使用 LinkedHashSet 存储随机数但有重复
- vba - VBA Excel表格公式参考
- jenkins - 使用 for 循环的并行 jenkins 作业
- mysql - 大数据表中的Mysql查询
- ios - 将应用程序从 GCM 更新到 FCM 后,iOS 设备未收到推送通知
- java - Android Studio Osmand 项目
- python - Python pandas: groupby and devide by the first value of each group
- c++ - 如何修复用于根据参数返回不同类型的模板类中的错误 C2679?