Package org.skyscreamer.jsonassert
Class JSONCompare
- java.lang.Object
-
- org.skyscreamer.jsonassert.JSONCompare
-
public final class JSONCompare extends java.lang.ObjectProvides API to compare two JSON entities. This is the backend toJSONAssert, but it can be programmed against directly to access the functionality. (eg, to make something that works with a non-JUnit test framework)
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static JSONCompareResultcompareJson(JSONString expected, JSONString actual)ComparesJSONStringprovided to the expectedJSONString, checking that theJSONString.toJSONString()are equal.static JSONCompareResultcompareJSON(java.lang.String expectedStr, java.lang.String actualStr, JSONComparator comparator)Compares JSON string provided to the expected JSON string using provided comparator, and returns the results of the comparison.static JSONCompareResultcompareJSON(java.lang.String expectedStr, java.lang.String actualStr, JSONCompareMode mode)Compares JSON string provided to the expected JSON string, and returns the results of the comparison.static JSONCompareResultcompareJSON(org.json.JSONArray expected, org.json.JSONArray actual, JSONComparator comparator)Compares JSON object provided to the expected JSON object using provided comparator, and returns the results of the comparison.static JSONCompareResultcompareJSON(org.json.JSONArray expected, org.json.JSONArray actual, JSONCompareMode mode)Compares JSONArray provided to the expected JSONArray, and returns the results of the comparison.static JSONCompareResultcompareJSON(org.json.JSONObject expected, org.json.JSONObject actual, JSONComparator comparator)Compares JSON object provided to the expected JSON object using provided comparator, and returns the results of the comparison.static JSONCompareResultcompareJSON(org.json.JSONObject expected, org.json.JSONObject actual, JSONCompareMode mode)Compares JSONObject provided to the expected JSONObject, and returns the results of the comparison.
-
-
-
Method Detail
-
compareJSON
public static JSONCompareResult compareJSON(java.lang.String expectedStr, java.lang.String actualStr, JSONComparator comparator) throws org.json.JSONException
Compares JSON string provided to the expected JSON string using provided comparator, and returns the results of the comparison.- Parameters:
expectedStr- Expected JSON stringactualStr- JSON string to comparecomparator- Comparator to use- Returns:
- result of the comparison
- Throws:
org.json.JSONException- JSON parsing errorjava.lang.IllegalArgumentException- when type of expectedStr doesn't match the type of actualStr
-
compareJSON
public static JSONCompareResult compareJSON(org.json.JSONObject expected, org.json.JSONObject actual, JSONComparator comparator) throws org.json.JSONException
Compares JSON object provided to the expected JSON object using provided comparator, and returns the results of the comparison.- Parameters:
expected- expected json objectactual- actual json objectcomparator- comparator to use- Returns:
- result of the comparison
- Throws:
org.json.JSONException- JSON parsing error
-
compareJSON
public static JSONCompareResult compareJSON(org.json.JSONArray expected, org.json.JSONArray actual, JSONComparator comparator) throws org.json.JSONException
Compares JSON object provided to the expected JSON object using provided comparator, and returns the results of the comparison.- Parameters:
expected- expected json arrayactual- actual json arraycomparator- comparator to use- Returns:
- result of the comparison
- Throws:
org.json.JSONException- JSON parsing error
-
compareJson
public static JSONCompareResult compareJson(JSONString expected, JSONString actual)
ComparesJSONStringprovided to the expectedJSONString, checking that theJSONString.toJSONString()are equal.- Parameters:
expected- ExpectedJSONstringactual-JSONstringto compare- Returns:
- result of the comparison
-
compareJSON
public static JSONCompareResult compareJSON(java.lang.String expectedStr, java.lang.String actualStr, JSONCompareMode mode) throws org.json.JSONException
Compares JSON string provided to the expected JSON string, and returns the results of the comparison.- Parameters:
expectedStr- Expected JSON stringactualStr- JSON string to comparemode- Defines comparison behavior- Returns:
- result of the comparison
- Throws:
org.json.JSONException- JSON parsing error
-
compareJSON
public static JSONCompareResult compareJSON(org.json.JSONObject expected, org.json.JSONObject actual, JSONCompareMode mode) throws org.json.JSONException
Compares JSONObject provided to the expected JSONObject, and returns the results of the comparison.- Parameters:
expected- Expected JSONObjectactual- JSONObject to comparemode- Defines comparison behavior- Returns:
- result of the comparison
- Throws:
org.json.JSONException- JSON parsing error
-
compareJSON
public static JSONCompareResult compareJSON(org.json.JSONArray expected, org.json.JSONArray actual, JSONCompareMode mode) throws org.json.JSONException
Compares JSONArray provided to the expected JSONArray, and returns the results of the comparison.- Parameters:
expected- Expected JSONArrayactual- JSONArray to comparemode- Defines comparison behavior- Returns:
- result of the comparison
- Throws:
org.json.JSONException- JSON parsing error
-
-