How to respond with HTTP 400 error in a Spring MVC @ResponseBody method returning String?

I’m using Spring MVC for a simple JSON API, with @ResponseBody based approach like the following. (I already have a service layer producing JSON directly.) @RequestMapping(value = “/matches/{matchId}”, produces = “application/json”) @ResponseBody public String match(@PathVariable String matchId) { String json = matchService.getMatchJson(matchId); if (json == null) { // TODO: how to respond with e.g. 400 … Read more