Search code examples
javajsongroovyjsonassert

Ignore specific attributes when comparing two json files


I have been successfully using JSONAssert to compare two json responses like this:

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

I now need to ignore certain attributes as described here:

Ignore specific nodes/attributes while comparing two JSONs My new statement is:

JSONAssert.assertEquals(response2, getResponseBodyContent(), new CustomComparator(JSONCompareMode.LENIENT, new Customization("EffectiveEpochDate", (o1, o2) -> true)));

and I am getting the following errors:

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.

I am using a testing tool called Katalon that supports java/groovy. Any input would be appreciated. Thanks


Solution

  • 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}