jsonassert

Compare JSON response using JUnit and JSONassert

为君一笑 提交于 2020-06-26 06:50:07
问题 I'm relatively new to Java and I'm asking to write test of JSON response server. I found JSONassert very useful but I didn't succeed to write the method getRESTData . Anybody can help please? @Test public void testGetFriends() throws JSONException { JSONObject data = getRESTData("/friends/367.json"); String expected = "{friends:[{id:123,name:\"Corby Page\"}" + ",{id:456,name:\"Solomon Duskis\"}]}"; JSONAssert.assertEquals(expected, data, false); } 回答1: You can get the data as String and pass

finding json diff fails using JSONAssert

江枫思渺然 提交于 2020-06-09 05:40:57
问题 I was hoping to use Jackson to find JSON diff but it does not give detailed error messages. So I tried using JSOnAssert to find the diff between two JSON strings. JSONAssert.assertEquals(expectedJsonResponse, actualJsonResponse, false); Sadly, it does not appear to match correctly and give the detailed error messages as in the examples. If you have used it, Can you please clarify? java.lang.AssertionError: data[0] Could not find match for element {"errors":[{"httpStatus":"BAD_REQUEST",

Ignore specific nodes/attributes while comparing two JSONs

一曲冷凌霜 提交于 2019-12-20 12:15:10
问题 I want to compare two JSON strings which is a huge hierarchy and want to know where they differ in values. But some values are generated at runtime and are dynamic. I want to ignore those particular nodes from my comparison. I am currently using JSONAssert from org.SkyScreamer to do the comparison. It gives me nice console output but does not ignore any attributes. for ex. java.lang.AssertionError messageHeader.sentTime expected:null got:09082016 18:49:41.123 Now this comes dynamic and should

Ignore specific nodes/attributes while comparing two JSONs

梦想的初衷 提交于 2019-12-03 03:23:05
I want to compare two JSON strings which is a huge hierarchy and want to know where they differ in values. But some values are generated at runtime and are dynamic. I want to ignore those particular nodes from my comparison. I am currently using JSONAssert from org.SkyScreamer to do the comparison. It gives me nice console output but does not ignore any attributes. for ex. java.lang.AssertionError messageHeader.sentTime expected:null got:09082016 18:49:41.123 Now this comes dynamic and should be ignored. Something like JSONAssert.assertEquals(expectedJSONString, actualJSONString