What is the difference between returning void and ResponseEntity<Void> in Spring Boot RestController?

1.7k Views Asked by At

I wonder what the difference is between the return value of a Spring Boot RestController if void shall be returned?

I can see do difference in a test in either way. It seems that even if I return void the HttpStatus.NO_CONTENT (204) is returned to the requester as well as if I use ResponseEntity<Void>.

So, when I return void from an endpoint the HttpStatus is returned anyway and it doesn't matter if I choose void or ResponseEntity<Void>?

1

There are 1 best solutions below

3
On BEST ANSWER

Exactly. You would need the ResponseEntity<Void> if you want to add some headers.