Package com.devsoap.json
Class JsonAssert
java.lang.Object
org.assertj.core.api.AbstractAssert<JsonAssert,String>
com.devsoap.json.JsonAssert
- All Implemented Interfaces:
org.assertj.core.api.Assert<JsonAssert,
,String> org.assertj.core.api.Descriptable<JsonAssert>
,org.assertj.core.api.ExtensionPoints<JsonAssert,
String>
JSON Assertions
-
Field Summary
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself, objects, throwUnsupportedExceptionOnEquals
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGet field as array<ITEM> org.assertj.core.api.ListAssert
<ITEM> Get field as typed arrayasArray()
Assert root object is an array of objects<ITEM> org.assertj.core.api.ListAssert
<ITEM> Assert root object is an array of a single typestatic JsonAssert
assertThat
(Object object) Assert JSON on any object.static JsonAssert
assertThat
(String json) Assert JSON as a StringGet field or property by namefirstField
(String fieldName) Get the first field (or property) of a JSON objectGet the last field (or property) of a JSON objectGet the nth field (or property) of a JSON objectFind a field using a pathMethods inherited from class org.assertj.core.api.AbstractAssert
areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, hasToString, inBinary, inHexadecimal, is, isElementOfCustomAssert, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, usingRecursiveAssertion, usingRecursiveAssertion, usingRecursiveComparison, usingRecursiveComparison, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnError
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.assertj.core.api.Descriptable
as, as, as, describedAs, describedAs
-
Constructor Details
-
JsonAssert
Instantiates a new Json assert.- Parameters:
json
- the json as a string
-
-
Method Details
-
assertThat
Assert JSON as a String- Parameters:
json
- the json to assert on- Returns:
- the json assert
-
assertThat
Assert JSON on any object. Uses toString() to convert to a string- Parameters:
object
- the object- Returns:
- the json assert
-
asArray
Assert root object is an array of objects- Returns:
- the json array assert
- Throws:
AssertionError
- if field cannot be converted to Array
-
asArray
Assert root object is an array of a single type- Type Parameters:
ITEM
- the item type- Parameters:
itemClass
- the item class- Returns:
- the list assert
- Throws:
AssertionError
- if field cannot be converted to Array
-
firstField
Get the first field (or property) of a JSON object- Parameters:
fieldName
- the field or property name- Returns:
- the json value assert
- Throws:
AssertionError
- if field not found
-
lastField
Get the last field (or property) of a JSON object- Parameters:
fieldName
- the field or property name- Returns:
- the json value assert
- Throws:
AssertionError
- if field not found
-
nthField
Get the nth field (or property) of a JSON object- Parameters:
fieldName
- the field or property nameindex
- the zero based index- Returns:
- the json value assert
- Throws:
AssertionError
- if field not found
-
field
Get field or property by name- Parameters:
fieldName
- the field or property name- Returns:
- the json value assert
- Throws:
AssertionError
- if field not found
-
array
Get field as array- Parameters:
fieldName
- the field name- Returns:
- the json array assert
- Throws:
AssertionError
- if field is not found or is not an Array
-
array
Get field as typed array- Type Parameters:
ITEM
- the type parameter- Parameters:
fieldName
- the field nameitemClass
- the item class- Returns:
- the list assert
- Throws:
AssertionError
- if field not found, the field is not an array or the array types cannot be converted
-
path
Find a field using a path- Parameters:
fields
- the path segments- Returns:
- the json value assert
- Throws:
AssertionError
- if path not found
-