org.skyscreamer.jsonassert
Class JSONCompare

java.lang.Object
  extended by org.skyscreamer.jsonassert.JSONCompare

public final class JSONCompare
extends Object

Provides API to compare two JSON entities. This is the backend to JSONAssert, 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
static JSONCompareResult compareJSON(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 JSONCompareResult compareJSON(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 JSONCompareResult compareJSON(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 JSONCompareResult compareJSON(org.json.JSONObject expected, org.json.JSONObject actual, JSONCompareMode mode)
          Compares JSONObject provided to the expected JSONObject, and returns the results of the comparison.
static JSONCompareResult compareJson(org.json.JSONString expected, org.json.JSONString actual)
          Compares JSONString provided to the expected JSONString, checking that the JSONString.toJSONString() are equal.
static JSONCompareResult compareJSON(String expectedStr, String actualStr, JSONComparator comparator)
          Compares JSON string provided to the expected JSON string using provided comparator, and returns the results of the comparison.
static JSONCompareResult compareJSON(String expectedStr, String actualStr, JSONCompareMode mode)
          Compares JSON string provided to the expected JSON string, and returns the results of the comparison.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

compareJSON

public static JSONCompareResult compareJSON(String expectedStr,
                                            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 string
actualStr - JSON string to compare
comparator - Comparator to use
Returns:
result of the comparison
Throws:
org.json.JSONException
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 object
actual - actual json object
comparator - comparator to use
Returns:
result of the comparison
Throws:
org.json.JSONException

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 array
actual - actual json array
comparator - comparator to use
Returns:
result of the comparison
Throws:
org.json.JSONException

compareJson

public static JSONCompareResult compareJson(org.json.JSONString expected,
                                            org.json.JSONString actual)
Compares JSONString provided to the expected JSONString, checking that the JSONString.toJSONString() are equal.

Parameters:
expected - Expected JSONstring
actual - JSONstring to compare

compareJSON

public static JSONCompareResult compareJSON(String expectedStr,
                                            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 string
actualStr - JSON string to compare
mode - Defines comparison behavior
Throws:
org.json.JSONException

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 JSONObject
actual - JSONObject to compare
mode - Defines comparison behavior
Throws:
org.json.JSONException

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 JSONArray
actual - JSONArray to compare
mode - Defines comparison behavior
Throws:
org.json.JSONException


Copyright © 2013. All Rights Reserved.