Class JsonPathResultMatchers
An instance of this class is typically accessed via
MockMvcResultMatchers.jsonPath(String, Object...).
- Since:
- 3.2
- Author:
- Rossen Stoyanchev, Craig Andrews, Sam Brannen, Brian Clozel
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedJsonPathResultMatchers(String expression, Object... args) Protected constructor.
- 
Method SummaryModifier and TypeMethodDescriptionEvaluate the JSON path expression against the response content and assert that a non-null value does not exist at the given path.Evaluate the JSON path expression against the suppliedcontentand assert that a value, includingnullvalues, does not exist at the given path.exists()Evaluate the JSON path expression against the response content and assert that a non-null value, possibly an empty array or map, exists at the given path.Evaluate the JSON path expression against the response content and assert that a value, possiblynull, exists.isArray()Evaluate the JSON path expression against the response content and assert that the result is an array.Evaluate the JSON path expression against the response content and assert that the result is aBoolean.isEmpty()Evaluate the JSON path expression against the response content and assert that an empty value exists at the given path.isMap()Evaluate the JSON path expression against the response content and assert that the result is aMap.Evaluate the JSON path expression against the response content and assert that a non-empty value exists at the given path.isNumber()Evaluate the JSON path expression against the response content and assert that the result is aNumber.isString()Evaluate the JSON path expression against the response content and assert that the result is aString.Configures the currentJsonPathResultMatchersinstance to verify that the JSON payload is prepended with the given prefix.Evaluate the JSON path expression against the response content and assert that the result is equal to the supplied value.<T> ResultMatcherEvaluate the JSON path expression against the response content and assert the resulting value with the given HamcrestMatcher.<T> ResultMatcherAn overloaded variant ofvalue(Matcher)that also accepts a target type for the resulting value that the matcher can work reliably against.
- 
Constructor Details- 
JsonPathResultMatchersProtected constructor.Use MockMvcResultMatchers.jsonPath(String, Object...)orMockMvcResultMatchers.jsonPath(String, Matcher).- 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- 
prefixConfigures the currentJsonPathResultMatchersinstance to verify that the JSON payload is prepended with the given prefix.Use this method if the JSON payloads are prefixed to avoid Cross Site Script Inclusion (XSSI) attacks. - Parameters:
- prefix- the string prefix prepended to the actual JSON payload
- Since:
- 4.3
 
- 
valueEvaluate the JSON path expression against the response content and assert the resulting value with the given HamcrestMatcher.- See Also:
 
- 
valueAn overloaded variant ofvalue(Matcher)that also accepts a target type for the resulting value that the matcher can work reliably against.This can be useful for matching numbers reliably — for example, to coerce an integer into a double. - Since:
- 4.3.15
- See Also:
 
- 
valueEvaluate the JSON path expression against the response content and assert that the result is equal to the supplied value.- See Also:
 
- 
existsEvaluate the JSON path expression against the response content and assert that a non-null value, possibly an empty array or map, exists at the given path.If the JSON path expression is not definite, this method asserts that the value at the given path is not empty. 
- 
doesNotExistEvaluate the JSON path expression against the response content and assert that a non-null value does not exist at the given path.If the JSON path expression is not definite, this method asserts that the value at the given path is empty. 
- 
isEmptyEvaluate the JSON path expression against the response content and assert that an empty value exists at the given path.For the semantics of empty, consult the Javadoc for ObjectUtils.isEmpty(Object).- Since:
- 4.2.1
- See Also:
 
- 
isNotEmptyEvaluate the JSON path expression against the response content and assert that a non-empty value exists at the given path.For the semantics of empty, consult the Javadoc for ObjectUtils.isEmpty(Object).- Since:
- 4.2.1
- See Also:
 
- 
hasJsonPathEvaluate the JSON path expression against the response content and 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. - Since:
- 5.0.3
- See Also:
 
- 
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. - Since:
- 5.0.3
- See Also:
 
- 
isStringEvaluate the JSON path expression against the response content and assert that the result is aString.- Since:
- 4.2.1
 
- 
isBooleanEvaluate the JSON path expression against the response content and assert that the result is aBoolean.- Since:
- 4.2.1
 
- 
isNumberEvaluate the JSON path expression against the response content and assert that the result is aNumber.- Since:
- 4.2.1
 
- 
isArrayEvaluate the JSON path expression against the response content and assert that the result is an array.
- 
isMapEvaluate the JSON path expression against the response content and assert that the result is aMap.- Since:
- 4.2.1
 
 
-