-
Notifications
You must be signed in to change notification settings - Fork 203
Open
Description
According to JSONAssert {"Foo":1} == {"Foo":1.0}, but [{"Foo":1}] != [{"Foo":1.0}]. It seems to be deciding to use the number as a "unique key" to determine object identity within the array, which is an invalid assumption in this case.
I would expect JSONAssert to at least parse the value of each field when deciding if they are unequal across all objects in the array (and thus suitable to be used as the unique key).
Test case included below.
package com.example;
import org.json.JSONException;
import org.junit.Test;
import org.skyscreamer.jsonassert.JSONAssert;
public class TestJSONAssert
{
// This test fails
@Test
public void testArrayCompareDifferingPrecision() throws JSONException {
String actual = "[{ \"Foo\" : 1.0 }]";
String expected = "[{ \"Foo\" : 1 }]";
JSONAssert.assertEquals(expected, actual, false);
}
@Test
public void testArrayCompareSamePrecision() throws JSONException {
String actual = "[{ \"Foo\" : 1 }]";
String expected = "[{ \"Foo\" : 1 }]";
JSONAssert.assertEquals(expected, actual, false);
}
@Test
public void testObjectCompareDifferingPrecision() throws JSONException {
String actual = "{ \"Foo\" : 1.0 }";
String expected = "{ \"Foo\" : 1 }";
JSONAssert.assertEquals(expected, actual, false);
}
@Test
public void testObjectCompareSamePrecision() throws JSONException {
String actual = "{ \"Foo\" : 1 }";
String expected = "{ \"Foo\" : 1 }";
JSONAssert.assertEquals(expected, actual, false);
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels