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 ea193aac2c8..638390f13d9 100644 --- a/spring-web/src/main/java/org/springframework/http/ResponseEntity.java +++ b/spring-web/src/main/java/org/springframework/http/ResponseEntity.java @@ -246,6 +246,16 @@ public class ResponseEntity extends HttpEntity { return status(HttpStatus.NOT_FOUND); } + /** + * Create a builder with an + * {@linkplain HttpStatus#UNPROCESSABLE_ENTITY UNPROCESSABLE_ENTITY} status. + * @return the created builder + * @since 4.1.3 + */ + public static HeadersBuilder unprocessableEntity() { + return status(HttpStatus.UNPROCESSABLE_ENTITY); + } + /** * Defines a builder that adds headers to the response 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 1a59e8765a8..a58abf42fd9 100644 --- a/spring-web/src/test/java/org/springframework/http/ResponseEntityTests.java +++ b/spring-web/src/test/java/org/springframework/http/ResponseEntityTests.java @@ -26,6 +26,7 @@ import static org.junit.Assert.*; /** * @author Arjen Poutsma + * @author Marcel Overdijk */ public class ResponseEntityTests { @@ -119,6 +120,15 @@ public class ResponseEntityTests { assertNull(responseEntity.getBody()); } + @Test + public void unprocessableEntity() throws URISyntaxException { + ResponseEntity responseEntity = ResponseEntity.unprocessableEntity().build(); + + assertNotNull(responseEntity); + assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, responseEntity.getStatusCode()); + assertNull(responseEntity.getBody()); + } + @Test public void headers() throws URISyntaxException { String eTag = "\"foo\"";