比较两个json文件时忽略特定属性

时间:2019-11-15 18:22:54

标签: java json groovy jsonassert

我已经成功地使用JSONAssert来比较两个json响应,如下所示:

JSONAssert.assertEquals(response2.getResponseBodyContent(), response1.getResponseBodyContent(), JSONCompareMode.LENIENT)

我现在需要忽略某些属性,如下所述:

Ignore specific nodes/attributes while comparing two JSONs 我的新声明是:

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。任何输入将不胜感激。谢谢

1 个答案:

答案 0 :(得分:1)

您所引用的代码使用Java lambda语法(肯定不支持Groovy 2.5或更高版本的语法)。您必须改为通过闭包。例如。转动

(o1, o2) -> true

进入:

{a, b -> true}
相关问题