Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ResponseEntity.of(Optional) variant
When dealing with `Optional` values in a Controller handler (for example, values coming from a Spring Data repository), developers might reuse this code snippet quite often: ``` @GetMapping("/user") public ResponseEntity<Optional<User>> fetchUser() { Optional<User> user = //... return user.map(ResponseEntity::ok).orElse(notFound().build()); } ``` This commit adds a new static method on `ResponseEntity` for that, simplifying the previous snippet with `return ResponseEntity.of(user);` Note that in case more specific HTTP response headers are required by the application, developers should use other static methods to explicitly tell which headers should be used in each case. Issue: SPR-17187
- Loading branch information
Showing
2 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters