Class JsonPathExpectationsHelper
Based on the JsonPath project: requiring version 0.9+, with 1.1+ strongly recommended.
- Since:
- 3.2
- Author:
- Rossen Stoyanchev, Juergen Hoeller, Craig Andrews, Sam Brannen, Stephane Nicoll
- 
Constructor SummaryConstructorsConstructorDescriptionJsonPathExpectationsHelper(String expression) Construct a newJsonPathExpectationsHelperusing the default configuration.JsonPathExpectationsHelper(String expression, com.jayway.jsonpath.Configuration configuration) Construct a newJsonPathExpectationsHelper.JsonPathExpectationsHelper(String expression, Object... args) Deprecated, for removal: This API element is subject to removal in a future version.
- 
Method SummaryModifier and TypeMethodDescriptionvoidassertValue(String content, Object expectedValue) Evaluate the JSON path expression against the suppliedcontentand assert that the result is equal to the expected value.<T> voidassertValue(String content, Matcher<? super T> matcher) Evaluate the JSON path expression against the suppliedcontentand assert the resulting value with the givenMatcher.<T> voidassertValue(String content, Matcher<? super T> matcher, Class<T> targetType) An overloaded variant ofassertValue(String, Matcher)that also accepts a target type for the resulting value.<T> voidassertValue(String content, Matcher<? super T> matcher, ParameterizedTypeReference<T> targetType) An overloaded variant ofassertValue(String, Matcher)that also accepts a target type for the resulting value that allows generic types to be defined.voidassertValueIsArray(String content) Evaluate the JSON path expression against the suppliedcontentand assert that the resulting value is an array.voidassertValueIsBoolean(String content) Evaluate the JSON path expression against the suppliedcontentand assert that the resulting value is aBoolean.voidassertValueIsEmpty(String content) Evaluate the JSON path expression against the suppliedcontentand assert that an empty value exists at the given path.voidassertValueIsMap(String content) Evaluate the JSON path expression against the suppliedcontentand assert that the resulting value is aMap.voidassertValueIsNotEmpty(String content) Evaluate the JSON path expression against the suppliedcontentand assert that a non-empty value exists at the given path.voidassertValueIsNumber(String content) Evaluate the JSON path expression against the suppliedcontentand assert that the resulting value is aNumber.voidassertValueIsString(String content) Evaluate the JSON path expression against the suppliedcontentand assert that the resulting value is aString.voiddoesNotExist(String content) Evaluate the JSON path expression against the suppliedcontentand assert that a non-null value does not exist at the given path.voiddoesNotHaveJsonPath(String content) Evaluate the JSON path expression against the suppliedcontentand assert that a value, includingnullvalues, does not exist at the given path.evaluateJsonPath(String content) Evaluate the JSON path and return the resulting value.<T> TevaluateJsonPath(String content, Class<T> targetType) Variant ofevaluateJsonPath(String)with a target type.<T> TevaluateJsonPath(String content, ParameterizedTypeReference<T> targetType) Variant ofevaluateJsonPath(String)with a target type that has generics.voidEvaluate the JSON path expression against the suppliedcontentand assert that a non-null value, possibly an empty array or map, exists at the given path.voidhasJsonPath(String content) Evaluate the JSON path expression against the suppliedcontentand assert that a value, possiblynull, exists.
- 
Constructor Details- 
JsonPathExpectationsHelperConstruct a newJsonPathExpectationsHelperusing the default configuration.- Parameters:
- expression- the- JsonPathexpression; never- nullor empty
- Since:
- 6.2
 
- 
JsonPathExpectationsHelperpublic JsonPathExpectationsHelper(String expression, @Nullable com.jayway.jsonpath.Configuration configuration) Construct a newJsonPathExpectationsHelper.- Parameters:
- expression- the- JsonPathexpression; never- nullor empty
- configuration- the- Configurationto use or- nullto use the default configuration
- Since:
- 6.2
 
- 
JsonPathExpectationsHelper@Deprecated(since="6.2", forRemoval=true) public JsonPathExpectationsHelper(String expression, Object... args) Deprecated, for removal: This API element is subject to removal in a future version.in favor of callingString.formatted(Object...)upfrontConstruct a newJsonPathExpectationsHelper.- Parameters:
- expression- the- JsonPathexpression; never- nullor empty
- args- arguments to parameterize the- JsonPathexpression with, using formatting specifiers defined in- String.format(String, Object...)
 
 
- 
- 
Method Details- 
assertValueEvaluate the JSON path expression against the suppliedcontentand assert the resulting value with the givenMatcher.- Parameters:
- content- the JSON content
- matcher- the matcher with which to assert the result
 
- 
assertValueAn overloaded variant ofassertValue(String, Matcher)that also accepts a target type for the resulting value. This can be useful for matching numbers reliably for example coercing an integer into a double.- Parameters:
- content- the JSON content
- matcher- the matcher with which to assert the result
- targetType- the expected type of the resulting value
- Since:
- 4.3.3
 
- 
assertValuepublic <T> void assertValue(String content, Matcher<? super T> matcher, ParameterizedTypeReference<T> targetType) An overloaded variant ofassertValue(String, Matcher)that also accepts a target type for the resulting value that allows generic types to be defined.This must be used with a Configurationthat defines a more elaborateMappingProvideras the default one cannot handle generic types.- Parameters:
- content- the JSON content
- matcher- the matcher with which to assert the result
- targetType- the expected type of the resulting value
- Since:
- 6.2
 
- 
assertValueEvaluate the JSON path expression against the suppliedcontentand assert that the result is equal to the expected value.- Parameters:
- content- the JSON content
- expectedValue- the expected value
 
- 
assertValueIsStringEvaluate the JSON path expression against the suppliedcontentand assert that the resulting value is aString.- Parameters:
- content- the JSON content
- Since:
- 4.2.1
 
- 
assertValueIsBooleanEvaluate the JSON path expression against the suppliedcontentand assert that the resulting value is aBoolean.- Parameters:
- content- the JSON content
- Since:
- 4.2.1
 
- 
assertValueIsNumberEvaluate the JSON path expression against the suppliedcontentand assert that the resulting value is aNumber.- Parameters:
- content- the JSON content
- Since:
- 4.2.1
 
- 
assertValueIsArrayEvaluate the JSON path expression against the suppliedcontentand assert that the resulting value is an array.- Parameters:
- content- the JSON content
 
- 
assertValueIsMapEvaluate the JSON path expression against the suppliedcontentand assert that the resulting value is aMap.- Parameters:
- content- the JSON content
- Since:
- 4.2.1
 
- 
existsEvaluate the JSON path expression against the suppliedcontentand assert that a non-null value, possibly an empty array or map, exists at the given path.Note that if the JSON path expression is not definite, this method asserts that the list of values at the given path is not empty. - Parameters:
- content- the JSON content
 
- 
doesNotExistEvaluate the JSON path expression against the suppliedcontentand assert that a non-null value does not exist at the given path.Note that if the JSON path expression is not definite, this method asserts that the list of values at the given path is empty. - Parameters:
- content- the JSON content
 
- 
assertValueIsEmptyEvaluate the JSON path expression against the suppliedcontentand assert that an empty value exists at the given path.For the semantics of empty, consult the Javadoc for ObjectUtils.isEmpty(Object).- Parameters:
- content- the JSON content
 
- 
assertValueIsNotEmptyEvaluate the JSON path expression against the suppliedcontentand assert that a non-empty value exists at the given path.For the semantics of empty, consult the Javadoc for ObjectUtils.isEmpty(Object).- Parameters:
- content- the JSON content
 
- 
hasJsonPathEvaluate the JSON path expression against the suppliedcontentand assert that a value, possiblynull, exists.If the JSON path expression is not definite, this method asserts that the list of values at the given path is not empty. - Parameters:
- content- the JSON content
- Since:
- 5.0.3
 
- 
doesNotHaveJsonPathEvaluate the JSON path expression against the suppliedcontentand assert that a value, includingnullvalues, does not exist at the given path.If the JSON path expression is not definite, this method asserts that the list of values at the given path is empty. - Parameters:
- content- the JSON content
- Since:
- 5.0.3
 
- 
evaluateJsonPathEvaluate the JSON path and return the resulting value.- Parameters:
- content- the content to evaluate against
- Returns:
- the result of the evaluation
- Throws:
- AssertionError- if the evaluation fails
 
- 
evaluateJsonPathVariant ofevaluateJsonPath(String)with a target type.This can be useful for matching numbers reliably for example coercing an integer into a double or when the configured MappingProvidercan handle more complex object structures.- Parameters:
- content- the content to evaluate against
- targetType- the requested target type
- Returns:
- the result of the evaluation
- Throws:
- AssertionError- if the evaluation fails
 
- 
evaluateJsonPathVariant ofevaluateJsonPath(String)with a target type that has generics.This must be used with a Configurationthat defines a more elaborateMappingProvideras the default one cannot handle generic types.- Parameters:
- content- the content to evaluate against
- targetType- the requested target type
- Returns:
- the result of the evaluation
- Throws:
- AssertionError- if the evaluation fails
- Since:
- 6.2
 
 
- 
String.formatted(Object...)upfront