@ RobotKeyword public boolean jsonShouldBeEqual ( String from , String to , boolean useExactMatch , String method , String data , String contentType ) throws Exception { System . out . println ( "*DEBUG* Comparing JSON sources" ) ; boolean equal = false ; String fromJson = requestUtil . readSource ( from , method , data , contentType ) ; String toJson = requestUtil . readSource ( to , method , data , contentType ) ; if ( StringUtils . isNotBlank ( fromJson ) && StringUtils . isNotBlank ( toJson ) ) { if ( useExactMatch ) { if ( fromJson . equals ( toJson ) ) { System . out . println ( "*DEBUG* JSON strings are equal by exact compare" ) ; equal = true ; } else { System . out . println ( "*ERROR* JSON strings are NOT equal by exact compare" ) ; equal = false ; throw new JsonNotEqualException ( "JSON strings are NOT equal by exact compare" ) ; } } else { equal = diff . compare ( fromJson , toJson ) ; if ( ! equal ) { throw new JsonNotEqualException ( "JSON strings are NOT equal by compare" ) ; } } } else { System . out . println ( "*ERROR* Either from or to JSON was empty" ) ; throw new JsonNotValidException ( "One of the JSON strings is empty" ) ; } return equal ; }
Checks if the given JSON contents are equal . The third parameter specifies whether exact string match should be used or diffing by the JSON objects ie . the order of the attributes does not matter .