Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResponseEntity builders should allow casting an empty body to any type [SPR-14939] #19506

spring-projects-issues opened this issue Nov 23, 2016 · 0 comments


Copy link

@spring-projects-issues spring-projects-issues commented Nov 23, 2016

Rossen Stoyanchev opened SPR-14939 and commented

A ResponseEntity can be created for any body type without a body, e.g. new ResponseEntity<Foo>(HttpStatus.OK). The same however is not possible when using ResponseEntity builders where a ResponseEntity<Void> is returned for an empty body.

This makes the following impossible:

public ResponseEntity<Foo> handle(@PathVariable Long id) {
    Foo foo = getFoo(id);
    if (foo != null) {
        return ResponseEntity.ok(foo);
    else {
        return ResponseEntity.notFound().build(); // Incompatible types compilation error

The report is based on use case brought up in #19443.

Affects: 4.3.4, 5.0 M3

Issue Links:

  • #19443 Returning Mono<ResponseEntity<?>> causes NPE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.