类 JsonPathResultMatchers
- java.lang.Object
- org.springframework.test.web.servlet.result.JsonPathResultMatchers
public class JsonPathResultMatchers extends Object
Factory for assertions on the response content using JsonPath expressions.An instance of this class is typically accessed via
MockMvcResultMatchers.jsonPath(String, Matcher)
orMockMvcResultMatchers.jsonPath(String, Object...)
.- 从以下版本开始:
- 3.2
- 作者:
- Rossen Stoyanchev, Craig Andrews, Sam Brannen, Brian Clozel
构造器概要
构造器 限定符 构造器 说明 protected
JsonPathResultMatchers(String expression, Object... args)
Protected constructor.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 ResultMatcher
doesNotExist()
Evaluate the JSON path expression against the response content and assert that a value 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 exists at the given path.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 aBoolean
.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 aMap
.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 aNumber
.ResultMatcher
isString()
Evaluate the JSON path expression against the response content and assert that the result is aString
.JsonPathResultMatchers
prefix(String prefix)
Configures the currentJsonPathResultMatchers
instance to verify that the JSON payload is prepended with the given prefix.ResultMatcher
value(Object expectedValue)
Evaluate the JSON path expression against the response content and assert that the result is equal to the supplied value.<T> ResultMatcher
value(Matcher<T> matcher)
Evaluate the JSON path expression against the response content and assert the resulting value with the given HamcrestMatcher
.<T> ResultMatcher
value(Matcher<T> matcher, Class<T> targetType)
An overloaded variant ofvalue(Matcher)
that also accepts a target type for the resulting value that the matcher can work reliably against.
构造器详细资料
JsonPathResultMatchers
protected JsonPathResultMatchers(String expression, Object... args)
Protected constructor.Use
MockMvcResultMatchers.jsonPath(String, Object...)
orMockMvcResultMatchers.jsonPath(String, Matcher)
.- 参数:
expression
- theJsonPath
expression; nevernull
or emptyargs
- arguments to parameterize theJsonPath
expression with, using formatting specifiers defined inString.format(String, Object...)
方法详细资料
prefix
public JsonPathResultMatchers prefix(String prefix)
Configures the currentJsonPathResultMatchers
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 payload- 从以下版本开始:
- 4.3
value
public <T> ResultMatcher value(Matcher<T> matcher)
Evaluate the JSON path expression against the response content and assert the resulting value with the given HamcrestMatcher
.
value
public <T> ResultMatcher value(Matcher<T> matcher, Class<T> targetType)
An 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.
- 从以下版本开始:
- 4.3.15
- 另请参阅:
value(Matcher)
,value(Object)
value
public ResultMatcher value(Object expectedValue)
Evaluate the JSON path expression against the response content and assert that the result is equal to the supplied value.
exists
public ResultMatcher exists()
Evaluate the JSON path expression against the response content and assert that a non-null value 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.
doesNotExist
public ResultMatcher doesNotExist()
Evaluate the JSON path expression against the response content and assert that a 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.
isEmpty
public ResultMatcher isEmpty()
Evaluate 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)
.- 从以下版本开始:
- 4.2.1
- 另请参阅:
isNotEmpty()
,exists()
,doesNotExist()
isNotEmpty
public ResultMatcher isNotEmpty()
Evaluate 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)
.- 从以下版本开始:
- 4.2.1
- 另请参阅:
isEmpty()
,exists()
,doesNotExist()
isString
public ResultMatcher isString()
Evaluate the JSON path expression against the response content and assert that the result is aString
.- 从以下版本开始:
- 4.2.1
isBoolean
public ResultMatcher isBoolean()
Evaluate the JSON path expression against the response content and assert that the result is aBoolean
.- 从以下版本开始:
- 4.2.1
isNumber
public ResultMatcher isNumber()
Evaluate the JSON path expression against the response content and assert that the result is aNumber
.- 从以下版本开始:
- 4.2.1
isArray
public ResultMatcher isArray()
Evaluate the JSON path expression against the response content and assert that the result is an array.
isMap
public ResultMatcher isMap()
Evaluate the JSON path expression against the response content and assert that the result is aMap
.- 从以下版本开始:
- 4.2.1