Interface JsonComparator
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Strategy interface used to compare JSON strings.
Use of(JsonCompareMode) for a comparator backed by the JSON
assertion library available on the classpath, or provide a custom
implementation to use another library or configuration.
- Since:
- 6.2
- Author:
- Phillip Webb
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidassertIsMatch(@Nullable String expectedJson, @Nullable String actualJson) Assert that theexpectedJsonmatches the comparison rules of ths instance against theactualJson.Compare the given JSON strings.static JsonComparatorof(JsonCompareMode compareMode) Create aJsonComparatorfor the givenJsonCompareMode, backed by the JSON assertion library available on the classpath.
-
Method Details
-
compare
Compare the given JSON strings.- Parameters:
expectedJson- the expected JSONactualJson- the actual JSON- Returns:
- the JSON comparison
-
assertIsMatch
Assert that theexpectedJsonmatches the comparison rules of ths instance against theactualJson. Throw anAssertionErrorif the comparison does not match.- Parameters:
expectedJson- the expected JSONactualJson- the actual JSON
-
of
Create aJsonComparatorfor the givenJsonCompareMode, backed by the JSON assertion library available on the classpath.JsonUnit (
net.javacrumbs.json-unit:json-unit-core) is used if present, otherwise JSONassert (org.skyscreamer:jsonassert).- Parameters:
compareMode- the compare mode to use- Returns:
- a new
JsonComparatorinstance - Throws:
IllegalStateException- if neither library is present- Since:
- 7.1
-