diff --git a/spring-web/src/main/java/org/springframework/http/ResponseEntity.java b/spring-web/src/main/java/org/springframework/http/ResponseEntity.java index 638390f13d..1c1f3fe290 100644 --- a/spring-web/src/main/java/org/springframework/http/ResponseEntity.java +++ b/spring-web/src/main/java/org/springframework/http/ResponseEntity.java @@ -252,7 +252,7 @@ public class ResponseEntity extends HttpEntity { * @return the created builder * @since 4.1.3 */ - public static HeadersBuilder unprocessableEntity() { + public static BodyBuilder unprocessableEntity() { return status(HttpStatus.UNPROCESSABLE_ENTITY); } diff --git a/spring-web/src/test/java/org/springframework/http/ResponseEntityTests.java b/spring-web/src/test/java/org/springframework/http/ResponseEntityTests.java index a58abf42fd..e4c0f7c84a 100644 --- a/spring-web/src/test/java/org/springframework/http/ResponseEntityTests.java +++ b/spring-web/src/test/java/org/springframework/http/ResponseEntityTests.java @@ -122,11 +122,11 @@ public class ResponseEntityTests { @Test public void unprocessableEntity() throws URISyntaxException { - ResponseEntity responseEntity = ResponseEntity.unprocessableEntity().build(); + ResponseEntity responseEntity = ResponseEntity.unprocessableEntity().body("error"); assertNotNull(responseEntity); assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, responseEntity.getStatusCode()); - assertNull(responseEntity.getBody()); + assertEquals("error", responseEntity.getBody()); } @Test