Imagine this simple controller method :
public ResponseEntity<?> findById(@Parameter(description = "id") @PathVariable String id) {
Optional<Model> model = repository.findById(id);
if(model.isEmpty()) {
return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body("Model not found");
}
return ResponseEntity.status(HttpStatus.OK)
.body(model.get());
}
It returns the model if it is found or an error string message if not. The case could be more complexe then this.
So I'm returning a String
or a Model
types, which could not be bound to the generic type of ResponseEntity
.
My question is why spring team designed this class as a generic type ? or am I using wrong this object ?