Package org.skyscreamer.jsonassert
Enum JSONCompareMode
- java.lang.Object
-
- java.lang.Enum<JSONCompareMode>
-
- org.skyscreamer.jsonassert.JSONCompareMode
-
- All Implemented Interfaces:
Serializable
,Comparable<JSONCompareMode>
public enum JSONCompareMode extends Enum<JSONCompareMode>
These different modes define different behavior for the comparison of JSON for testing. Each mode encapsulates two underlying behaviors: extensibility and strict ordering.
Extensible Strict Ordering STRICT no yes LENIENT yes no NON_EXTENSIBLE no no STRICT_ORDER yes yes If extensibility not allowed, then all of the expected values must match in what's being tested, but any additional fields will cause the test to fail. When extensibility is allowed, all values must still match. For example, if you're expecting:
{id:1,name:"Carter"}
Then the following will pass when extensible, and will fail when not:
{id:1,name:"Carter",favoriteColor:"blue"}
If strict ordering is enabled, JSON arrays must be in strict sequence. For example, if you're expecting:
{id:1,friends:[{id:2},{id:3}]}
Then the following will fail strict ordering, but will otherwise pass:
{id:1,friends:[{id:3},{id:2}]}
-
-
Enum Constant Summary
Enum Constants Enum Constant Description LENIENT
Lenient checking.NON_EXTENSIBLE
Non-extensible checking.STRICT
Strict checking.STRICT_ORDER
Strict order checking.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
hasStrictOrder()
Strict order requiredboolean
isExtensible()
Is extensiblestatic JSONCompareMode
valueOf(String name)
Returns the enum constant of this type with the specified name.static JSONCompareMode[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.JSONCompareMode
withExtensible(boolean extensible)
Get the equivalentJSONCompareMode
with or without extensibility.JSONCompareMode
withStrictOrdering(boolean strictOrdering)
Get the equivalentJSONCompareMode
with or without strict ordering.
-
-
-
Enum Constant Detail
-
STRICT
public static final JSONCompareMode STRICT
Strict checking. Not extensible, and strict array ordering.
-
LENIENT
public static final JSONCompareMode LENIENT
Lenient checking. Extensible, and non-strict array ordering.
-
NON_EXTENSIBLE
public static final JSONCompareMode NON_EXTENSIBLE
Non-extensible checking. Not extensible, and non-strict array ordering.
-
STRICT_ORDER
public static final JSONCompareMode STRICT_ORDER
Strict order checking. Extensible, and strict array ordering.
-
-
Method Detail
-
values
public static JSONCompareMode[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (JSONCompareMode c : JSONCompareMode.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static JSONCompareMode valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
isExtensible
public boolean isExtensible()
Is extensible- Returns:
- True if results can be extended from what's expected, otherwise false.
-
hasStrictOrder
public boolean hasStrictOrder()
Strict order required- Returns:
- True if results require strict array ordering, otherwise false.
-
withStrictOrdering
public JSONCompareMode withStrictOrdering(boolean strictOrdering)
Get the equivalentJSONCompareMode
with or without strict ordering.- Parameters:
strictOrdering
- if true, requires strict ordering of array elements- Returns:
- the equivalent
JSONCompareMode
-
withExtensible
public JSONCompareMode withExtensible(boolean extensible)
Get the equivalentJSONCompareMode
with or without extensibility.- Parameters:
extensible
- if true, allows keys in actual that don't appear in expected- Returns:
- the equivalent
JSONCompareMode
-
-