Compare commits

...

8 Commits

Author SHA1 Message Date
Sean Leary
8439039da7 Update pom.xml
For the 20220924 release
2022-09-24 16:25:18 -05:00
Sean Leary
a6bdd081eb Update RELEASES.md 2022-09-24 16:13:11 -05:00
Sean Leary
a30d71fdca Update README.md 2022-09-24 16:11:12 -05:00
Sean Leary
cdd67b0aef Merge pull request #688 from stleary/update-copyright
#688 update copyright
2022-08-26 21:07:52 -05:00
stleary
89f6e7f6a6 Merge branch 'master' into update-copyright 2022-08-26 20:59:00 -05:00
Sean Leary
346fb26f2d Merge pull request #683 from spaffrath/Issue_682_JSONString_similarity
Issue 682 JSONString similarity
2022-08-26 20:57:22 -05:00
spaffrath
7dd9e01dae Merge branch 'stleary:master' into Issue_682_JSONString_similarity 2022-08-20 07:51:30 -07:00
Scott Paffrath
89f16ad0af Issue 682 JSONString similarity 2022-08-05 11:00:33 -07:00
7 changed files with 58 additions and 2 deletions

View File

@@ -8,7 +8,7 @@ JSON in Java [package org.json]
[![Maven Central](https://img.shields.io/maven-central/v/org.json/json.svg)](https://mvnrepository.com/artifact/org.json/json) [![Maven Central](https://img.shields.io/maven-central/v/org.json/json.svg)](https://mvnrepository.com/artifact/org.json/json)
**[Click here if you just want the latest release jar file.](https://search.maven.org/remotecontent?filepath=org/json/json/20220320/json-20220320.jar)** **[Click here if you just want the latest release jar file.](https://search.maven.org/remotecontent?filepath=org/json/json/20220924/json-20220924.jar)**
# Overview # Overview

View File

@@ -5,6 +5,8 @@ and artifactId "json". For example:
[https://search.maven.org/search?q=g:org.json%20AND%20a:json&core=gav](https://search.maven.org/search?q=g:org.json%20AND%20a:json&core=gav) [https://search.maven.org/search?q=g:org.json%20AND%20a:json&core=gav](https://search.maven.org/search?q=g:org.json%20AND%20a:json&core=gav)
~~~ ~~~
20220924 New License - public domain, and some minor updates
20220320 Wrap StackOverflow with JSONException 20220320 Wrap StackOverflow with JSONException
20211205 Recent commits and some bug fixes for similar() 20211205 Recent commits and some bug fixes for similar()

View File

@@ -3,7 +3,7 @@
<groupId>org.json</groupId> <groupId>org.json</groupId>
<artifactId>json</artifactId> <artifactId>json</artifactId>
<version>20220320</version> <version>20220924</version>
<packaging>bundle</packaging> <packaging>bundle</packaging>
<name>JSON in Java</name> <name>JSON in Java</name>

View File

@@ -1366,6 +1366,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;
} }

View File

@@ -2125,6 +2125,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;
} }

View File

@@ -6,6 +6,7 @@ Public Domain.
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;
@@ -29,7 +30,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;
@@ -1334,4 +1337,25 @@ public class JSONArrayTest {
fail("Excepected Exception."); fail("Excepected Exception.");
Util.checkJSONArrayMaps(json_input); Util.checkJSONArrayMaps(json_input);
} }
@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));
}
} }

View File

@@ -30,6 +30,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;
@@ -3487,4 +3488,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));
}
} }