I have a controller
@RestController
public class BookController {
@GetMapping("/find-by-name/{name}")
public ResponseEntity<BookEntity> findByName(@PathVariable String name) {
...
if the name is found, then in this method I return
return ResponseEntity.ok(book);
if not, then
return new ResponseEntity("name= " + name + " not found", HttpStatus.NOT_ACCEPTABLE);
Everything works, but the compiler swears:
Raw use of parameterized class 'ResponseEntity'
Unchecked assignment: 'org.springframework.http.ResponseEntity' to 'org.springframework.http.ResponseEntity<BookEntity>'
Unchecked call to 'ResponseEntity(T, HttpStatus)' as a member of raw type 'org.springframework.http.ResponseEntity'
I tried to do this (I found this option on the website spring.io)
public ResponseEntity<?> findByName(@PathVariable String name) {
...
return new ResponseEntity<>("name= " + name + " not found", HttpStatus.NOT_ACCEPTABLE);
That error is gone, but now swears on this line:
Generic wildcard types should not be used in return types
The code works in both versions, but I would like to understand how to implement it correctly.