diff --git a/spring-test/src/main/java/org/springframework/test/web/support/AbstractJsonPathAssertions.java b/spring-test/src/main/java/org/springframework/test/web/support/AbstractJsonPathAssertions.java index 2254d39abb0..b2e842aec09 100644 --- a/spring-test/src/main/java/org/springframework/test/web/support/AbstractJsonPathAssertions.java +++ b/spring-test/src/main/java/org/springframework/test/web/support/AbstractJsonPathAssertions.java @@ -58,7 +58,7 @@ public abstract class AbstractJsonPathAssertions { /** * Applies {@link JsonPathExpectationsHelper#assertValue(String, Object)}. */ - public B isEqualTo(Object expectedValue) { + public B isEqualTo(@Nullable Object expectedValue) { this.pathHelper.assertValue(this.content, expectedValue); return this.bodySpec; } diff --git a/spring-test/src/test/java/org/springframework/test/util/JsonPathExpectationsHelperTests.java b/spring-test/src/test/java/org/springframework/test/util/JsonPathExpectationsHelperTests.java index f1c0f00e8d7..d4a4b52672a 100644 --- a/spring-test/src/test/java/org/springframework/test/util/JsonPathExpectationsHelperTests.java +++ b/spring-test/src/test/java/org/springframework/test/util/JsonPathExpectationsHelperTests.java @@ -60,7 +60,8 @@ class JsonPathExpectationsHelperTests { 'whitespace': ' ', 'emptyString': '', 'emptyArray': [], - 'emptyMap': {} + 'emptyMap': {}, + 'nullValue': null }"""; private static final String SIMPSONS = """ @@ -252,6 +253,11 @@ class JsonPathExpectationsHelperTests { new JsonPathExpectationsHelper("$.num").assertValue(CONTENT, 5); } + @Test + void assertNullValue() { + new JsonPathExpectationsHelper("$.nullValue").assertValue(CONTENT, (Object) null); + } + @Test // SPR-14498 void assertValueWithNumberConversion() { new JsonPathExpectationsHelper("$.num").assertValue(CONTENT, 5.0);