I want to return an error when the body of a REST request is empty (e.g contains only {}
) but there is no way to detect if the request body contains an empty JSON or not.
I tried to change @RequestBody(required = true)
but it's not working.
@PatchMapping("{id}")
public ResponseEntity<Book> updateAdvisor(@PathVariable("id") Integer id,
@Valid @RequestBody BookDto newBook) {
Book addedBook = bookService.updateBook(newBook);
return new ResponseEntity<>(addedBook,HttpStatus.OK);
}
If the body sent contains an empty JSON I should return an exception. If the body is not empty and at least one element is provided I won't return an error.