skyscreamer / JSONassert

Write JSON unit tests in less code. Great for testing REST interfaces.
http://jsonassert.skyscreamer.org
Apache License 2.0
1k stars 197 forks source link

JsonAssert.assertEquals Faliure #64

Closed adityagautam closed 8 years ago

adityagautam commented 8 years ago

Error that I am getting: While the values of both the strings are same. but still assertion is failing. Expected: a JSON object but none found

Code: JSONParser parser = new JSONParser(); try

    {

      JSONArray jsonArray = (JSONArray) parser.parse(new FileReader("/path_to_file"));

       String abc = jsonArray.toJSONString();

        Headers allHeaders = response.getHeaders();
        Gson gson = new Gson();
        String headerList = gson.toJson(allHeaders.getList("Session"));
        JSONArray jsonArray2 = (JSONArray) parser.parse(headerList);
        String abcd = jsonArray2.toJSONString();

JSONAssert.assertEquals(abc,abcd,false);

carterpage commented 8 years ago

Not sure what you're actually comparing. Try printing out abc and abcd, create code compare the raw strings (String abc = "...") and add here. That will be easier to troubleshoot.

carterpage commented 8 years ago

Going to close, but feel free to reopen with the actual strings if you still haven't resolved this.