public class JsonPathResultMatchers extends Object
An instance of this class is typically accessed via
MockMvcResultMatchers.jsonPath(String, Matcher)
or
MockMvcResultMatchers.jsonPath(String, Object...)
.
Modifier | Constructor and Description |
---|---|
protected |
JsonPathResultMatchers(String expression,
Object... args)
Protected constructor.
|
Modifier and Type | Method and Description |
---|---|
ResultMatcher |
doesNotExist()
Evaluate the JSON path expression against the response content and
assert that a non-null value does not exist at the given path.
|
ResultMatcher |
doesNotHaveJsonPath()
Evaluate the JSON path expression against the supplied
content
and assert that a value, including null values, does not exist
at the given path. |
ResultMatcher |
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.
|
ResultMatcher |
hasJsonPath()
Evaluate the JSON path expression against the response content
and assert that a value, possibly
null , exists. |
ResultMatcher |
isArray()
Evaluate the JSON path expression against the response content and
assert that the result is an array.
|
ResultMatcher |
isBoolean()
Evaluate the JSON path expression against the response content and
assert that the result is a
Boolean . |
ResultMatcher |
isEmpty()
Evaluate the JSON path expression against the response content and
assert that an empty value exists at the given path.
|
ResultMatcher |
isMap()
Evaluate the JSON path expression against the response content and
assert that the result is a
Map . |
ResultMatcher |
isNotEmpty()
Evaluate the JSON path expression against the response content and
assert that a non-empty value exists at the given path.
|
ResultMatcher |
isNumber()
Evaluate the JSON path expression against the response content and
assert that the result is a
Number . |
ResultMatcher |
isString()
Evaluate the JSON path expression against the response content and
assert that the result is a
String . |
JsonPathResultMatchers |
prefix(String prefix)
Configures the current
JsonPathResultMatchers instance
to verify that the JSON payload is prepended with the given prefix. |
<T> ResultMatcher |
value(Matcher<T> matcher)
Evaluate the JSON path expression against the response content and
assert the resulting value with the given Hamcrest
Matcher . |
<T> ResultMatcher |
value(Matcher<T> matcher,
Class<T> targetType)
An overloaded variant of
value(Matcher) that also accepts a
target type for the resulting value that the matcher can work reliably
against. |
ResultMatcher |
value(Object expectedValue)
Evaluate the JSON path expression against the response content and
assert that the result is equal to the supplied value.
|
protected JsonPathResultMatchers(String expression, Object... args)
Use MockMvcResultMatchers.jsonPath(String, Object...)
or
MockMvcResultMatchers.jsonPath(String, Matcher)
.
expression
- the JsonPath
expression; never null
or emptyargs
- arguments to parameterize the JsonPath
expression with,
using formatting specifiers defined in String.format(String, Object...)
public JsonPathResultMatchers prefix(String prefix)
JsonPathResultMatchers
instance
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.
prefix
- the string prefix prepended to the actual JSON payloadpublic <T> ResultMatcher value(Matcher<T> matcher)
Matcher
.value(Matcher, Class)
,
value(Object)
public <T> ResultMatcher value(Matcher<T> matcher, Class<T> targetType)
value(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.
value(Matcher)
,
value(Object)
public ResultMatcher value(Object expectedValue)
value(Matcher)
,
value(Matcher, Class)
public ResultMatcher exists()
If the JSON path expression is not definite, this method asserts that the value at the given path is not empty.
public ResultMatcher doesNotExist()
If the JSON path expression is not definite, this method asserts that the value at the given path is empty.
public ResultMatcher isEmpty()
For the semantics of empty, consult the Javadoc for
ObjectUtils.isEmpty(Object)
.
isNotEmpty()
,
exists()
,
doesNotExist()
public ResultMatcher isNotEmpty()
For the semantics of empty, consult the Javadoc for
ObjectUtils.isEmpty(Object)
.
isEmpty()
,
exists()
,
doesNotExist()
public ResultMatcher hasJsonPath()
null
, exists.
If the JSON path expression is not definite, this method asserts that the list of values at the given path is not empty.
exists()
,
isNotEmpty()
public ResultMatcher doesNotHaveJsonPath()
content
and assert that a value, including null
values, 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.
doesNotExist()
,
isEmpty()
public ResultMatcher isString()
String
.public ResultMatcher isBoolean()
Boolean
.public ResultMatcher isNumber()
Number
.public ResultMatcher isArray()
public ResultMatcher isMap()
Map
.