你如何强制 Spring MVC4 REST web 服务只接受 json 格式的参数?

How do you force Spring MVC4 REST webservices to only accept parameters in json format?

有没有办法强制 Spring MVC4 REST 网络服务接受特定格式的参数或请求?我希望我的网络服务仅通过将参数附加到 url 端点来接受 JSON 参数。我尝试了下面的示例,但您可以通过 url 传递参数 我希望他们以干净的 json 格式传递它 我如何在 spring.

中执行此操作
 @RequestMapping(value = "/user/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<User> getUser(@PathVariable("id") long id) {
    System.out.println("Fetching User with id " + id);
    User user = userService.findById(id);
    if (user == null) {
        System.out.println("User with id " + id + " not found");
        return new ResponseEntity<User>(HttpStatus.NOT_FOUND);
    }
    return new ResponseEntity<User>(user, HttpStatus.OK);
}
@RequestMapping(value = "/user/{id}", 
        method = RequestMethod.GET, 
        produces = MediaType.APPLICATION_JSON_VALUE, 
        consumes = MediaType.APPLICATION_JSON_VALUE)
 @RequestMapping(...,consumes= MediaType.APPLICATION_JSON_VALUE)