Class AbstractJsonContentAssert<SELF extends AbstractJsonContentAssert<SELF>>
- Type Parameters:
- SELF- the type of assertions
- All Implemented Interfaces:
- org.assertj.core.api.Assert<SELF,,- JsonContent> - org.assertj.core.api.Descriptable<SELF>,- org.assertj.core.api.ExtensionPoints<SELF,- JsonContent> 
- Direct Known Subclasses:
- JsonContentAssert
Supports evaluating JSON path expressions and extracting a part of the document for further assertions on the value.
Also supports comparing the JSON document against a target, using a
 JSON Comparator. Resources that are loaded from
 the classpath can be relative if a class is provided. By default, UTF-8 is used to load resources,
 but this can be overridden using withCharset(Charset).
- Since:
- 6.2
- Author:
- Stephane Nicoll, Phillip Webb, Andy Wilkinson, Diego Berrueta, Camille Vienot
- 
Field SummaryFields inherited from class org.assertj.core.api.AbstractAssertactual, info, myself, objects, throwUnsupportedExceptionOnEquals
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedAbstractJsonContentAssert(JsonContent actual, Class<?> selfType) Create an assert for the given JSON document.
- 
Method SummaryModifier and TypeMethodDescription<T> org.assertj.core.api.AbstractObjectAssert<?,T> Verify that the actual value can be converted to an instance of the giventarget, and produce a new assertion object narrowed to that type.<ASSERT extends org.assertj.core.api.AbstractAssert<?,?>> 
 ASSERTconvertTo(org.assertj.core.api.AssertFactory<?, ASSERT> assertFactory) Verify that the actual value can be converted to an instance of the type defined by the givenAssertFactoryand return a new Assert narrowed to that type.doesNotHavePath(String path) Verify that the given JSONpathdoes not match.extractingPath(String path) Verify that the given JSONpathis present, and extract the JSON value for further assertions.Verify that the given JSONpathmatches.hasPathSatisfying(String path, Consumer<org.assertj.core.api.AssertProvider<JsonPathValueAssert>> valueRequirements) Verify that the given JSONpathis present with a JSON value satisfying the givenvalueRequirements.isEqualTo(CharSequence expected) Verify that the actual value is strictly equal to the given JSON.isEqualTo(CharSequence expected, JsonComparator comparator) Verify that the actual value is equal to the given JSON.isEqualTo(CharSequence expected, JsonCompareMode compareMode) Verify that the actual value is equal to the given JSON.isEqualTo(Resource expected, JsonComparator comparator) Verify that the actual value is equal to the given JSONResource.isEqualTo(Resource expected, JsonCompareMode compareMode) Verify that the actual value is equal to the given JSONResource.isLenientlyEqualTo(CharSequence expected) Verify that the actual value islenientlyequal to the given JSON.isLenientlyEqualTo(Resource expected) isNotEqualTo(CharSequence expected) Verify that the actual value is strictly not equal to the given JSON.isNotEqualTo(CharSequence expected, JsonComparator comparator) Verify that the actual value is not equal to the given JSON.isNotEqualTo(CharSequence expected, JsonCompareMode compareMode) Verify that the actual value is not equal to the given JSON.isNotEqualTo(Resource expected, JsonComparator comparator) Verify that the actual value is not equal to the given JSONResource.isNotEqualTo(Resource expected, JsonCompareMode compareMode) Verify that the actual value is not equal to the given JSONResource.isNotLenientlyEqualTo(CharSequence expected) Verify that the actual value is notlenientlyequal to the given JSON.isNotLenientlyEqualTo(Resource expected) isNotStrictlyEqualTo(CharSequence expected) Verify that the actual value is notstrictlyequal to the given JSON.isNotStrictlyEqualTo(Resource expected) isStrictlyEqualTo(CharSequence expected) Verify that the actual value isstrictlyequal to the given JSON.isStrictlyEqualTo(Resource expected) withCharset(Charset charset) Override theCharsetto use to load resources.withResourceLoadClass(Class<?> resourceLoadClass) Override the class used to load resources.Methods inherited from class org.assertj.core.api.AbstractObjectAssertas, as, doesNotReturn, extracting, extracting, extracting, extracting, extracting, extracting, extractingForProxy, getComparatorsByType, hasAllNullFieldsOrProperties, hasAllNullFieldsOrPropertiesExcept, hasFieldOrProperty, hasFieldOrPropertyWithValue, hasNoNullFieldsOrProperties, hasNoNullFieldsOrPropertiesExcept, hasOnlyFields, isEqualToComparingFieldByField, isEqualToComparingFieldByFieldRecursively, isEqualToComparingOnlyGivenFields, isEqualToIgnoringGivenFields, isEqualToIgnoringNullFields, newObjectAssert, returns, usingComparatorForFields, usingComparatorForType, usingRecursiveAssertion, usingRecursiveAssertion, usingRecursiveComparison, usingRecursiveComparisonMethods inherited from class org.assertj.core.api.AbstractAssertactual, areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, doesNotMatch, doesNotMatch, 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, usingEquals, usingEquals, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnErrorMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.assertj.core.api.Descriptableas, describedAs, describedAs
- 
Constructor Details- 
AbstractJsonContentAssertCreate an assert for the given JSON document.- Parameters:
- actual- the JSON document to assert
- selfType- the implementation type of this assert
 
 
- 
- 
Method Details- 
convertToVerify that the actual value can be converted to an instance of the giventarget, and produce a new assertion object narrowed to that type.- Parameters:
- target- the type to convert the actual value to
 
- 
convertTopublic <ASSERT extends org.assertj.core.api.AbstractAssert<?,?>> ASSERT convertTo(org.assertj.core.api.AssertFactory<?, ASSERT> assertFactory) Verify that the actual value can be converted to an instance of the type defined by the givenAssertFactoryand return a new Assert narrowed to that type.InstanceOfAssertFactoriesprovides static factories for all the types supported byAssertions.assertThat(java.util.function.Predicate<T>). Additional factories can be created by implementingAssertFactory.Example: // Check that the JSON document is an array of 3 users assertThat(json).convertTo(InstanceOfAssertFactories.list(User.class)) hasSize(3); // ListAssert of User- Parameters:
- assertFactory- the- AssertFactoryto use to produce a narrowed Assert for the type that it defines.
 
- 
extractingPathVerify that the given JSONpathis present, and extract the JSON value for further assertions.- Parameters:
- path- the- JsonPathexpression
- See Also:
 
- 
hasPathSatisfyingpublic SELF hasPathSatisfying(String path, Consumer<org.assertj.core.api.AssertProvider<JsonPathValueAssert>> valueRequirements) Verify that the given JSONpathis present with a JSON value satisfying the givenvalueRequirements.- Parameters:
- path- the- JsonPathexpression
- valueRequirements- a- Consumerof the assertion object
 
- 
hasPathVerify that the given JSONpathmatches. For paths with an operator, this validates that the path expression is valid, but does not validate that it yield any results.- Parameters:
- path- the- JsonPathexpression
 
- 
doesNotHavePathVerify that the given JSONpathdoes not match.- Parameters:
- path- the- JsonPathexpression
 
- 
isEqualToVerify that the actual value is strictly equal to the given JSON. Theexpectedvalue can contain the JSON itself or, if it ends with.json, the name of a resource to be loaded from the classpath.- Parameters:
- expected- the expected JSON or the name of a resource containing the expected JSON
- See Also:
 
- 
isEqualToVerify that the actual value is equal to the given JSON. Theexpectedvalue can contain the JSON itself or, if it ends with.json, the name of a resource to be loaded from the classpath.- Parameters:
- expected- the expected JSON or the name of a resource containing the expected JSON
- compareMode- the compare mode used when checking
 
- 
isEqualToVerify that the actual value is equal to the given JSONResource.The resource abstraction allows to provide several input types: - a bytearray, usingByteArrayResource
- a classpathresource, usingClassPathResource
- a FileorPath, usingFileSystemResource
- an InputStream, usingInputStreamResource
 - Parameters:
- expected- a resource containing the expected JSON
- compareMode- the compare mode used when checking
 
- a 
- 
isEqualToVerify that the actual value is equal to the given JSON. Theexpectedvalue can contain the JSON itself or, if it ends with.json, the name of a resource to be loaded from the classpath.- Parameters:
- expected- the expected JSON or the name of a resource containing the expected JSON
- comparator- the comparator used when checking
 
- 
isEqualToVerify that the actual value is equal to the given JSONResource.The resource abstraction allows to provide several input types: - a bytearray, usingByteArrayResource
- a classpathresource, usingClassPathResource
- a FileorPath, usingFileSystemResource
- an InputStream, usingInputStreamResource
 - Parameters:
- expected- a resource containing the expected JSON
- comparator- the comparator used when checking
 
- a 
- 
isLenientlyEqualToVerify that the actual value islenientlyequal to the given JSON. Theexpectedvalue can contain the JSON itself or, if it ends with.json, the name of a resource to be loaded from the classpath.- Parameters:
- expected- the expected JSON or the name of a resource containing the expected JSON
 
- 
isLenientlyEqualToVerify that the actual value islenientlyequal to the given JSONResource.The resource abstraction allows to provide several input types: - a bytearray, usingByteArrayResource
- a classpathresource, usingClassPathResource
- a FileorPath, usingFileSystemResource
- an InputStream, usingInputStreamResource
 - Parameters:
- expected- a resource containing the expected JSON
 
- a 
- 
isStrictlyEqualToVerify that the actual value isstrictlyequal to the given JSON. Theexpectedvalue can contain the JSON itself or, if it ends with.json, the name of a resource to be loaded from the classpath.- Parameters:
- expected- the expected JSON or the name of a resource containing the expected JSON
 
- 
isStrictlyEqualToVerify that the actual value isstrictlyequal to the given JSONResource.The resource abstraction allows to provide several input types: - a bytearray, usingByteArrayResource
- a classpathresource, usingClassPathResource
- a FileorPath, usingFileSystemResource
- an InputStream, usingInputStreamResource
 - Parameters:
- expected- a resource containing the expected JSON
 
- a 
- 
isNotEqualToVerify that the actual value is strictly not equal to the given JSON. Theexpectedvalue can contain the JSON itself or, if it ends with.json, the name of a resource to be loaded from the classpath.- Parameters:
- expected- the expected JSON or the name of a resource containing the expected JSON
- See Also:
 
- 
isNotEqualToVerify that the actual value is not equal to the given JSON. Theexpectedvalue can contain the JSON itself or, if it ends with.json, the name of a resource to be loaded from the classpath.- Parameters:
- expected- the expected JSON or the name of a resource containing the expected JSON
- compareMode- the compare mode used when checking
 
- 
isNotEqualToVerify that the actual value is not equal to the given JSONResource.The resource abstraction allows to provide several input types: - a bytearray, usingByteArrayResource
- a classpathresource, usingClassPathResource
- a FileorPath, usingFileSystemResource
- an InputStream, usingInputStreamResource
 - Parameters:
- expected- a resource containing the expected JSON
- compareMode- the compare mode used when checking
 
- a 
- 
isNotEqualToVerify that the actual value is not equal to the given JSON. Theexpectedvalue can contain the JSON itself or, if it ends with.json, the name of a resource to be loaded from the classpath.- Parameters:
- expected- the expected JSON or the name of a resource containing the expected JSON
- comparator- the comparator used when checking
 
- 
isNotEqualToVerify that the actual value is not equal to the given JSONResource.The resource abstraction allows to provide several input types: - a bytearray, usingByteArrayResource
- a classpathresource, usingClassPathResource
- a FileorPath, usingFileSystemResource
- an InputStream, usingInputStreamResource
 - Parameters:
- expected- a resource containing the expected JSON
- comparator- the comparator used when checking
 
- a 
- 
isNotLenientlyEqualToVerify that the actual value is notlenientlyequal to the given JSON. Theexpectedvalue can contain the JSON itself or, if it ends with.json, the name of a resource to be loaded from the classpath.- Parameters:
- expected- the expected JSON or the name of a resource containing the expected JSON
 
- 
isNotLenientlyEqualToVerify that the actual value is notlenientlyequal to the given JSONResource.The resource abstraction allows to provide several input types: - a bytearray, usingByteArrayResource
- a classpathresource, usingClassPathResource
- a FileorPath, usingFileSystemResource
- an InputStream, usingInputStreamResource
 - Parameters:
- expected- a resource containing the expected JSON
 
- a 
- 
isNotStrictlyEqualToVerify that the actual value is notstrictlyequal to the given JSON. Theexpectedvalue can contain the JSON itself or, if it ends with.json, the name of a resource to be loaded from the classpath.- Parameters:
- expected- the expected JSON or the name of a resource containing the expected JSON
 
- 
isNotStrictlyEqualToVerify that the actual value is notstrictlyequal to the given JSONResource.The resource abstraction allows to provide several input types: - a bytearray, usingByteArrayResource
- a classpathresource, usingClassPathResource
- a FileorPath, usingFileSystemResource
- an InputStream, usingInputStreamResource
 - Parameters:
- expected- a resource containing the expected JSON
 
- a 
- 
withResourceLoadClassOverride the class used to load resources.Resources can be loaded from an absolute location or relative to the specified class. For instance, specifying com.example.MyClassas the resource class allows you to use "my-file.json" to load/com/example/my-file.json.- Parameters:
- resourceLoadClass- the class used to load resources, or- nullto only use absolute paths
 
- 
withCharsetOverride theCharsetto use to load resources.By default, resources are loaded using UTF-8.- Parameters:
- charset- the charset to use, or- nullto use the default
 
 
-