spring-framework / org.springframework.test.web.servlet.result / JsonPathResultMatchers

JsonPathResultMatchers

open class JsonPathResultMatchers

Factory for assertions on the response content using JsonPath expressions.

An instance of this class is typically accessed via MockMvcResultMatchers#jsonPath(String, Matcher) or MockMvcResultMatchers#jsonPath(String, Object...).

Author
Rossen Stoyanchev

Author
Craig Andrews

Author
Sam Brannen

Author
Brian Clozel

Since
3.2

Functions

doesNotExist

open fun doesNotExist(): ResultMatcher

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.

exists

open fun exists(): ResultMatcher

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.

isArray

open fun isArray(): ResultMatcher

Evaluate the JSON path expression against the response content and assert that the result is an array.

isBoolean

open fun isBoolean(): ResultMatcher

Evaluate the JSON path expression against the response content and assert that the result is a Boolean.

isEmpty

open fun isEmpty(): ResultMatcher

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 org.springframework.util.ObjectUtils#isEmpty(Object).

isMap

open fun isMap(): ResultMatcher

Evaluate the JSON path expression against the response content and assert that the result is a java.util.Map.

isNotEmpty

open fun isNotEmpty(): ResultMatcher

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 org.springframework.util.ObjectUtils#isEmpty(Object).

isNumber

open fun isNumber(): ResultMatcher

Evaluate the JSON path expression against the response content and assert that the result is a Number.

isString

open fun isString(): ResultMatcher

Evaluate the JSON path expression against the response content and assert that the result is a String.

prefix

open fun prefix(prefix: String): JsonPathResultMatchers

Configures the current 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.

value

open fun <T : Any> value(matcher: Matcher<T>): ResultMatcher

Evaluate the JSON path expression against the response content and assert the resulting value with the given Hamcrest Matcher.

open fun value(expectedValue: Any): ResultMatcher

Evaluate the JSON path expression against the response content and assert that the result is equal to the supplied value.