I prefer to do something like this:
- The rest end point will receive an request with data then,
- Business service class is called with the data
- Validate the data if invalid throw an exception with proper description, e.g.:
throw new InvalidArgumentException("invalid objet Id"); - On controller if above exception is thrown then return 400 Bad Request with error description e.g.:
{"ok":false, "error":"invalid_argument","msg":"invalid objet Id"}
By doing this way the business class can be used anywhere and response can be handled accordingly.