Skip to content

Issue when comparing JSONArray if any value is null #105

Open
@anantharaman93

Description

@anantharaman93

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)

Activity

added a commit that references this issue on Nov 18, 2020

Merge pull request #111 from suraj1291993/master

d889f22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @anantharaman93

        Issue actions

          Issue when comparing JSONArray if any value is null · Issue #105 · skyscreamer/JSONassert