mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-03 03:15:32 -04:00
Issue 682 JSONString similarity
This commit is contained in:
parent
6f92a3ab4e
commit
89f16ad0af
@ -1386,6 +1386,10 @@ public class JSONArray implements Iterable<Object> {
|
|||||||
if (!JSONObject.isNumberSimilar((Number)valueThis, (Number)valueOther)) {
|
if (!JSONObject.isNumberSimilar((Number)valueThis, (Number)valueOther)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else if (valueThis instanceof JSONString && valueOther instanceof JSONString) {
|
||||||
|
if (!((JSONString) valueThis).toJSONString().equals(((JSONString) valueOther).toJSONString())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
} else if (!valueThis.equals(valueOther)) {
|
} else if (!valueThis.equals(valueOther)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -2142,6 +2142,10 @@ public class JSONObject {
|
|||||||
if (!isNumberSimilar((Number)valueThis, (Number)valueOther)) {
|
if (!isNumberSimilar((Number)valueThis, (Number)valueOther)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else if (valueThis instanceof JSONString && valueOther instanceof JSONString) {
|
||||||
|
if (!((JSONString) valueThis).toJSONString().equals(((JSONString) valueOther).toJSONString())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
} else if (!valueThis.equals(valueOther)) {
|
} else if (!valueThis.equals(valueOther)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ SOFTWARE.
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@ -49,7 +50,9 @@ import org.json.JSONArray;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONPointerException;
|
import org.json.JSONPointerException;
|
||||||
|
import org.json.JSONString;
|
||||||
import org.json.JSONTokener;
|
import org.json.JSONTokener;
|
||||||
|
import org.json.junit.data.MyJsonString;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.jayway.jsonpath.Configuration;
|
import com.jayway.jsonpath.Configuration;
|
||||||
@ -1298,4 +1301,25 @@ public class JSONArrayTest {
|
|||||||
assertNotNull(json_input);
|
assertNotNull(json_input);
|
||||||
fail("Excepected Exception.");
|
fail("Excepected Exception.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIssue682SimilarityOfJSONString() {
|
||||||
|
JSONArray ja1 = new JSONArray()
|
||||||
|
.put(new MyJsonString())
|
||||||
|
.put(2);
|
||||||
|
JSONArray ja2 = new JSONArray()
|
||||||
|
.put(new MyJsonString())
|
||||||
|
.put(2);
|
||||||
|
assertTrue(ja1.similar(ja2));
|
||||||
|
|
||||||
|
JSONArray ja3 = new JSONArray()
|
||||||
|
.put(new JSONString() {
|
||||||
|
@Override
|
||||||
|
public String toJSONString() {
|
||||||
|
return "\"different value\"";
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.put(2);
|
||||||
|
assertFalse(ja1.similar(ja3));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,7 @@ import org.json.JSONArray;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONPointerException;
|
import org.json.JSONPointerException;
|
||||||
|
import org.json.JSONString;
|
||||||
import org.json.JSONTokener;
|
import org.json.JSONTokener;
|
||||||
import org.json.XML;
|
import org.json.XML;
|
||||||
import org.json.junit.data.BrokenToString;
|
import org.json.junit.data.BrokenToString;
|
||||||
@ -3398,4 +3399,25 @@ public class JSONObjectTest {
|
|||||||
assertNotNull(json_input);
|
assertNotNull(json_input);
|
||||||
fail("Excepected Exception.");
|
fail("Excepected Exception.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIssue682SimilarityOfJSONString() {
|
||||||
|
JSONObject jo1 = new JSONObject()
|
||||||
|
.put("a", new MyJsonString())
|
||||||
|
.put("b", 2);
|
||||||
|
JSONObject jo2 = new JSONObject()
|
||||||
|
.put("a", new MyJsonString())
|
||||||
|
.put("b", 2);
|
||||||
|
assertTrue(jo1.similar(jo2));
|
||||||
|
|
||||||
|
JSONObject jo3 = new JSONObject()
|
||||||
|
.put("a", new JSONString() {
|
||||||
|
@Override
|
||||||
|
public String toJSONString() {
|
||||||
|
return "\"different value\"";
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.put("b", 2);
|
||||||
|
assertFalse(jo1.similar(jo3));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user