Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>?

like image 788
du-it Avatar asked Nov 01 '25 22:11

du-it


1 Answers

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

like image 120
Simon Martinelli Avatar answered Nov 03 '25 19:11

Simon Martinelli