Skip to content

Commit 8b9be3c

Browse files
authored
Finally moving to official org.json implementation! (#194)
* Replaced org.json with stleary/JSON-java library. * Checkpoint. Beginning to removing JSONException imports since it is now a RuntimeException. * Completed removal of explicit throws JSONException since it is now a RuntimeException. * Updated README to account for new dependency and removal of old. * One last unnecessary JSONException reference. * Library change breaks some behavior and is a major shift. Incrementing major version.
1 parent b1750da commit 8b9be3c

23 files changed

Lines changed: 259 additions & 431 deletions

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changelog
22
=========
33

4+
Version 2.0.0 - TBD
5+
-------------------
6+
- TODO - placeholder
7+
48
Version 1.5.3 - 6/28/2024
59
-------------------------
610
- Revert Java release version from 21 to 8 due to breaking older compilers.

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ To use, [download the JAR](https://github.com/skyscreamer/JSONassert/releases) o
7777
<dependency>
7878
<groupId>org.skyscreamer</groupId>
7979
<artifactId>jsonassert</artifactId>
80-
<version>1.5.3</version>
80+
<version>2.0.0-SNAPSHOT</version>
8181
<scope>test</scope>
8282
</dependency>
8383

@@ -97,16 +97,15 @@ Who uses JSONassert?
9797
+ [GroupDocs](http://groupdocs.com/)
9898
+ [Shazam](http://www.shazam.com/)
9999
+ [Thucydides](http://thucydides.net/)
100+
+ [and over a thousand more](https://mvnrepository.com/artifact/org.skyscreamer/jsonassert)...
100101

101102
* * *
102103

103104
org.json
104105
--------
105106

106-
This implementation uses a clean-room implementation of the org.json
107-
library implemented for the Android system, released under the Apache 2.0 license. See
108-
[com.vaadin.external.google:android-json](http://search.maven.org/#artifactdetails%7Ccom.vaadin.external.google%7Candroid-json%7C0.0.20131108.vaadin1%7Cjar)
109-
That jar does **not** include the org.json.JSONString interface, so a new implementation of that interface is added to this source.
107+
As of v2, JSONAssert uses @stleary's [JSON-java](https://github.com/stleary/JSON-java) implementation of org.json, the
108+
most commonly used reference implementation for JSON in Java.
110109

111110
Resources
112111
---------

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>org.skyscreamer</groupId>
66
<artifactId>jsonassert</artifactId>
7-
<version>1.5.3</version>
7+
<version>2.0.0-SNAPSHOT</version>
88
<packaging>jar</packaging>
99

1010
<name>JSONassert</name>
@@ -47,9 +47,9 @@
4747
<!-- For JSONAssert -->
4848
<dependencies>
4949
<dependency>
50-
<groupId>com.vaadin.external.google</groupId>
51-
<artifactId>android-json</artifactId>
52-
<version>0.0.20131108.vaadin1</version>
50+
<groupId>org.json</groupId>
51+
<artifactId>json</artifactId>
52+
<version>20240303</version>
5353
</dependency>
5454
<dependency>
5555
<groupId>junit</groupId>

src/main/java/org/json/JSONString.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/main/java/org/skyscreamer/jsonassert/JSONAssert.java

Lines changed: 56 additions & 144 deletions
Large diffs are not rendered by default.

src/main/java/org/skyscreamer/jsonassert/JSONCompare.java

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package org.skyscreamer.jsonassert;
1616

1717
import org.json.JSONArray;
18-
import org.json.JSONException;
1918
import org.json.JSONObject;
2019
import org.json.JSONString;
2120
import org.skyscreamer.jsonassert.comparator.DefaultComparator;
@@ -41,11 +40,9 @@ private static JSONComparator getComparatorForMode(JSONCompareMode mode) {
4140
* @param actualStr JSON string to compare
4241
* @param comparator Comparator to use
4342
* @return result of the comparison
44-
* @throws JSONException JSON parsing error
4543
* @throws IllegalArgumentException when type of expectedStr doesn't match the type of actualStr
4644
*/
47-
public static JSONCompareResult compareJSON(String expectedStr, String actualStr, JSONComparator comparator)
48-
throws JSONException {
45+
public static JSONCompareResult compareJSON(String expectedStr, String actualStr, JSONComparator comparator) {
4946
Object expected = JSONParser.parseJSON(expectedStr);
5047
Object actual = JSONParser.parseJSON(actualStr);
5148
if ((expected instanceof JSONObject) && (actual instanceof JSONObject)) {
@@ -72,10 +69,8 @@ else if (expected instanceof JSONObject) {
7269
* @param actual actual json object
7370
* @param comparator comparator to use
7471
* @return result of the comparison
75-
* @throws JSONException JSON parsing error
7672
*/
77-
public static JSONCompareResult compareJSON(JSONObject expected, JSONObject actual, JSONComparator comparator)
78-
throws JSONException {
73+
public static JSONCompareResult compareJSON(JSONObject expected, JSONObject actual, JSONComparator comparator) {
7974
return comparator.compareJSON(expected, actual);
8075
}
8176

@@ -86,10 +81,8 @@ public static JSONCompareResult compareJSON(JSONObject expected, JSONObject actu
8681
* @param actual actual json array
8782
* @param comparator comparator to use
8883
* @return result of the comparison
89-
* @throws JSONException JSON parsing error
9084
*/
91-
public static JSONCompareResult compareJSON(JSONArray expected, JSONArray actual, JSONComparator comparator)
92-
throws JSONException {
85+
public static JSONCompareResult compareJSON(JSONArray expected, JSONArray actual, JSONComparator comparator) {
9386
return comparator.compareJSON(expected, actual);
9487
}
9588

@@ -118,10 +111,8 @@ public static JSONCompareResult compareJson(final JSONString expected, final JSO
118111
* @param actualStr JSON string to compare
119112
* @param mode Defines comparison behavior
120113
* @return result of the comparison
121-
* @throws JSONException JSON parsing error
122114
*/
123-
public static JSONCompareResult compareJSON(String expectedStr, String actualStr, JSONCompareMode mode)
124-
throws JSONException {
115+
public static JSONCompareResult compareJSON(String expectedStr, String actualStr, JSONCompareMode mode) {
125116
return compareJSON(expectedStr, actualStr, getComparatorForMode(mode));
126117
}
127118

@@ -132,10 +123,8 @@ public static JSONCompareResult compareJSON(String expectedStr, String actualStr
132123
* @param actual JSONObject to compare
133124
* @param mode Defines comparison behavior
134125
* @return result of the comparison
135-
* @throws JSONException JSON parsing error
136126
*/
137-
public static JSONCompareResult compareJSON(JSONObject expected, JSONObject actual, JSONCompareMode mode)
138-
throws JSONException {
127+
public static JSONCompareResult compareJSON(JSONObject expected, JSONObject actual, JSONCompareMode mode) {
139128
return compareJSON(expected, actual, getComparatorForMode(mode));
140129
}
141130

@@ -147,10 +136,8 @@ public static JSONCompareResult compareJSON(JSONObject expected, JSONObject actu
147136
* @param actual JSONArray to compare
148137
* @param mode Defines comparison behavior
149138
* @return result of the comparison
150-
* @throws JSONException JSON parsing error
151139
*/
152-
public static JSONCompareResult compareJSON(JSONArray expected, JSONArray actual, JSONCompareMode mode)
153-
throws JSONException {
140+
public static JSONCompareResult compareJSON(JSONArray expected, JSONArray actual, JSONCompareMode mode) {
154141
return compareJSON(expected, actual, getComparatorForMode(mode));
155142
}
156143

src/main/java/org/skyscreamer/jsonassert/JSONParser.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ private JSONParser() {}
3636
*
3737
* @param s Raw JSON string to be parsed
3838
* @return JSONObject or JSONArray
39-
* @throws JSONException JSON parsing error
4039
*/
41-
public static Object parseJSON(final String s) throws JSONException {
40+
public static Object parseJSON(final String s) {
4241
if (s.trim().startsWith("{")) {
4342
return new JSONObject(s);
4443
}

src/main/java/org/skyscreamer/jsonassert/comparator/AbstractComparator.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package org.skyscreamer.jsonassert.comparator;
1616

1717
import org.json.JSONArray;
18-
import org.json.JSONException;
1918
import org.json.JSONObject;
2019
import org.skyscreamer.jsonassert.JSONCompareResult;
2120

@@ -42,10 +41,9 @@ public AbstractComparator() {
4241
*
4342
* @param expected Expected JSONObject
4443
* @param actual JSONObject to compare
45-
* @throws JSONException JSON parsing error
4644
*/
4745
@Override
48-
public final JSONCompareResult compareJSON(JSONObject expected, JSONObject actual) throws JSONException {
46+
public final JSONCompareResult compareJSON(JSONObject expected, JSONObject actual) {
4947
JSONCompareResult result = new JSONCompareResult();
5048
compareJSON("", expected, actual, result);
5149
return result;
@@ -56,10 +54,9 @@ public final JSONCompareResult compareJSON(JSONObject expected, JSONObject actua
5654
*
5755
* @param expected Expected JSONArray
5856
* @param actual JSONArray to compare
59-
* @throws JSONException JSON parsing error
6057
*/
6158
@Override
62-
public final JSONCompareResult compareJSON(JSONArray expected, JSONArray actual) throws JSONException {
59+
public final JSONCompareResult compareJSON(JSONArray expected, JSONArray actual) {
6360
JSONCompareResult result = new JSONCompareResult();
6461
compareJSONArray("", expected, actual, result);
6562
return result;
@@ -86,9 +83,8 @@ protected void checkJsonObjectKeysActualInExpected(String prefix, JSONObject exp
8683
* @param expected
8784
* @param actual
8885
* @param result
89-
* @throws JSONException
9086
*/
91-
protected void checkJsonObjectKeysExpectedInActual(String prefix, JSONObject expected, JSONObject actual, JSONCompareResult result) throws JSONException {
87+
protected void checkJsonObjectKeysExpectedInActual(String prefix, JSONObject expected, JSONObject actual, JSONCompareResult result) {
9288
Set<String> expectedKeys = getKeys(expected);
9389
for (String key : expectedKeys) {
9490
Object expectedValue = expected.get(key);
@@ -101,7 +97,7 @@ protected void checkJsonObjectKeysExpectedInActual(String prefix, JSONObject exp
10197
}
10298
}
10399

104-
protected void compareJSONArrayOfJsonObjects(String key, JSONArray expected, JSONArray actual, JSONCompareResult result) throws JSONException {
100+
protected void compareJSONArrayOfJsonObjects(String key, JSONArray expected, JSONArray actual, JSONCompareResult result) {
105101
String uniqueKey = findUniqueKey(expected);
106102
if (uniqueKey == null || !isUsableAsUniqueKey(uniqueKey, actual)) {
107103
// An expensive last resort
@@ -126,7 +122,7 @@ protected void compareJSONArrayOfJsonObjects(String key, JSONArray expected, JSO
126122
}
127123
}
128124

129-
protected void compareJSONArrayOfSimpleValues(String key, JSONArray expected, JSONArray actual, JSONCompareResult result) throws JSONException {
125+
protected void compareJSONArrayOfSimpleValues(String key, JSONArray expected, JSONArray actual, JSONCompareResult result) {
130126
Map<Object, Integer> expectedCount = JSONCompareUtil.getCardinalityMap(jsonArrayToList(expected));
131127
Map<Object, Integer> actualCount = JSONCompareUtil.getCardinalityMap(jsonArrayToList(actual));
132128
for (Object o : expectedCount.keySet()) {
@@ -144,7 +140,7 @@ protected void compareJSONArrayOfSimpleValues(String key, JSONArray expected, JS
144140
}
145141
}
146142

147-
protected void compareJSONArrayWithStrictOrder(String key, JSONArray expected, JSONArray actual, JSONCompareResult result) throws JSONException {
143+
protected void compareJSONArrayWithStrictOrder(String key, JSONArray expected, JSONArray actual, JSONCompareResult result) {
148144
for (int i = 0; i < expected.length(); ++i) {
149145
Object expectedValue = JSONCompareUtil.getObjectOrNull(expected, i);
150146
Object actualValue = JSONCompareUtil.getObjectOrNull(actual, i);
@@ -157,7 +153,7 @@ protected void compareJSONArrayWithStrictOrder(String key, JSONArray expected, J
157153
// This is expensive (O(n^2) -- yuck), but may be the only resort for some cases with loose array ordering, and no
158154
// easy way to uniquely identify each element.
159155
protected void recursivelyCompareJSONArray(String key, JSONArray expected, JSONArray actual,
160-
JSONCompareResult result) throws JSONException {
156+
JSONCompareResult result) {
161157
Set<Integer> matched = new HashSet<Integer>();
162158
for (int i = 0; i < expected.length(); ++i) {
163159
Object expectedElement = JSONCompareUtil.getObjectOrNull(expected, i);

src/main/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import java.text.MessageFormat;
1818

1919
import org.json.JSONArray;
20-
import org.json.JSONException;
2120
import org.skyscreamer.jsonassert.JSONCompareMode;
2221
import org.skyscreamer.jsonassert.JSONCompareResult;
2322

@@ -69,7 +68,7 @@ public ArraySizeComparator(JSONCompareMode mode) {
6968
*/
7069
@Override
7170
public void compareJSONArray(String prefix, JSONArray expected,
72-
JSONArray actual, JSONCompareResult result) throws JSONException {
71+
JSONArray actual, JSONCompareResult result) {
7372
String arrayPrefix = prefix + "[]";
7473
if (expected.length() < 1 || expected.length() > 2) {
7574
result.fail(MessageFormat

src/main/java/org/skyscreamer/jsonassert/comparator/CustomComparator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
package org.skyscreamer.jsonassert.comparator;
1616

17-
import org.json.JSONException;
1817
import org.skyscreamer.jsonassert.Customization;
1918
import org.skyscreamer.jsonassert.JSONCompareMode;
2019
import org.skyscreamer.jsonassert.JSONCompareResult;
@@ -33,7 +32,7 @@ public CustomComparator(JSONCompareMode mode, Customization... customizations)
3332
}
3433

3534
@Override
36-
public void compareValues(String prefix, Object expectedValue, Object actualValue, JSONCompareResult result) throws JSONException {
35+
public void compareValues(String prefix, Object expectedValue, Object actualValue, JSONCompareResult result) {
3736
Customization customization = getCustomization(prefix);
3837
if (customization != null) {
3938
try {

0 commit comments

Comments
 (0)