Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 9
    To be precise, you should return ResponseEntity<T>, where T is for example Response (first case in question). And you'll return new ResponseEntity(myResponse, HttpStatus.OK) when it is a correct response. Commented Nov 28, 2014 at 0:08
  • 1
    This way allows you to set headers as well, ResponseStatus doesn't, woot! Commented Jun 29, 2018 at 16:43
  • 1
    Another good thing about this is it doesn't result in warnings in the log, which throwing the ResponseStatusException does. Commented Sep 17, 2019 at 3:16
  • But then you lose the type on the Response, which won't work well with Swagger generated documentation. Commented Aug 20, 2020 at 10:34