Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue when comparing JSONArray if any value is null #105

Open
anantharaman93 opened this issue Aug 16, 2018 · 0 comments
Open

Issue when comparing JSONArray if any value is null #105

anantharaman93 opened this issue Aug 16, 2018 · 0 comments

Comments

@anantharaman93
Copy link

Hai,
I am getting the following exception when asserting 2 JSONArray objects if any of its value contains null. The code I used is

public class TestJSONassert
{
	public static void main(String args[])
	{
		JSONArray jsonArray1 = new JSONArray();
		jsonArray1.put(1);
		jsonArray1.put((Object)null);
		jsonArray1.put(3);
		jsonArray1.put(2);
		
		JSONArray jsonArray2 = new JSONArray();
		jsonArray2.put(1);
		jsonArray2.put((Object)null);
		jsonArray2.put(3);
		jsonArray2.put(2);
		
		JSONAssert.assertEquals(jsonArray1, jsonArray2, false);
	}
}

This causes exception

Exception in thread "main" org.json.JSONException: JSONArray[1] not found.
at org.json.JSONArray.get(JSONArray.java:194)
at org.skyscreamer.jsonassert.comparator.JSONCompareUtil.allSimpleValues(JSONCompareUtil.java:139)
at org.skyscreamer.jsonassert.comparator.DefaultComparator.compareJSONArray(DefaultComparator.java:82)
at org.skyscreamer.jsonassert.comparator.AbstractComparator.compareJSON(AbstractComparator.java:56)
at org.skyscreamer.jsonassert.JSONCompare.compareJSON(JSONCompare.java:93)
at org.skyscreamer.jsonassert.JSONCompare.compareJSON(JSONCompare.java:154)
at org.skyscreamer.jsonassert.JSONAssert.assertEquals(JSONAssert.java:724)
at org.skyscreamer.jsonassert.JSONAssert.assertEquals(JSONAssert.java:651)
at test.util.TestJSONassert.main(TestJSONassert.java:22)

anantharaman93 pushed a commit to anantharaman93/JSONassert that referenced this issue Oct 26, 2018
carterpage added a commit that referenced this issue Nov 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant