Browse Source

ResponseEntity headers builder casts body to any type

Issue: SPR-14939
pull/1257/head
Rossen Stoyanchev 9 years ago
parent
commit
dd3b9c7c35
  1. 4
      spring-web/src/main/java/org/springframework/http/ResponseEntity.java
  2. 19
      spring-web/src/test/java/org/springframework/http/ResponseEntityTests.java

4
spring-web/src/main/java/org/springframework/http/ResponseEntity.java

@ -381,7 +381,7 @@ public class ResponseEntity<T> extends HttpEntity<T> { @@ -381,7 +381,7 @@ public class ResponseEntity<T> extends HttpEntity<T> {
* @return the response entity
* @see BodyBuilder#body(Object)
*/
ResponseEntity<Void> build();
<T> ResponseEntity<T> build();
}
@ -505,7 +505,7 @@ public class ResponseEntity<T> extends HttpEntity<T> { @@ -505,7 +505,7 @@ public class ResponseEntity<T> extends HttpEntity<T> {
}
@Override
public ResponseEntity<Void> build() {
public <T> ResponseEntity<T> build() {
return body(null);
}

19
spring-web/src/test/java/org/springframework/http/ResponseEntityTests.java

@ -96,6 +96,15 @@ public class ResponseEntityTests { @@ -96,6 +96,15 @@ public class ResponseEntityTests {
assertNull(responseEntity.getBody());
}
@Test // SPR-14939
public void acceptedNoBodyWithAlternativeBodyType() throws URISyntaxException {
ResponseEntity<String> responseEntity = ResponseEntity.accepted().build();
assertNotNull(responseEntity);
assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode());
assertNull(responseEntity.getBody());
}
@Test
public void noContent() throws URISyntaxException {
ResponseEntity<Void> responseEntity = ResponseEntity.noContent().build();
@ -203,7 +212,7 @@ public class ResponseEntityTests { @@ -203,7 +212,7 @@ public class ResponseEntityTests {
@Test
public void emptyCacheControl() {
Integer entity = new Integer(42);
Integer entity = 42;
ResponseEntity<Integer> responseEntity =
ResponseEntity.status(HttpStatus.OK)
@ -218,7 +227,7 @@ public class ResponseEntityTests { @@ -218,7 +227,7 @@ public class ResponseEntityTests {
@Test
public void cacheControl() {
Integer entity = new Integer(42);
Integer entity = 42;
ResponseEntity<Integer> responseEntity =
ResponseEntity.status(HttpStatus.OK)
@ -236,7 +245,7 @@ public class ResponseEntityTests { @@ -236,7 +245,7 @@ public class ResponseEntityTests {
@Test
public void cacheControlNoCache() {
Integer entity = new Integer(42);
Integer entity = 42;
ResponseEntity<Integer> responseEntity =
ResponseEntity.status(HttpStatus.OK)
@ -254,7 +263,7 @@ public class ResponseEntityTests { @@ -254,7 +263,7 @@ public class ResponseEntityTests {
@Test
public void statusCodeAsInt() {
Integer entity = new Integer(42);
Integer entity = 42;
ResponseEntity<Integer> responseEntity = ResponseEntity.status(200).body(entity);
assertEquals(200, responseEntity.getStatusCode().value());
@ -263,7 +272,7 @@ public class ResponseEntityTests { @@ -263,7 +272,7 @@ public class ResponseEntityTests {
@Test
public void customStatusCode() {
Integer entity = new Integer(42);
Integer entity = 42;
ResponseEntity<Integer> responseEntity = ResponseEntity.status(299).body(entity);
assertEquals(299, responseEntity.getStatusCodeValue());

Loading…
Cancel
Save