So far I have done one project (REST) using Spring Boot and really enjoyed it. The only thing that seemed somewhat insidious to me was my understanding @RequestBody.
Suppose I have a POST method below to log into a user’s system. My user object may contain attributes other than the username and password that I need for a subsequent request. In this case, I did not see any other option than to make an additional object (LoginRequest) for storing data for incoming data.
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<User> login(@RequestBody LoginRequest request) {
User p = null;
if (request != null) {
p = User.login(request.getEmail(), request.getPassword()); // validates and returns user if exists
if (p != null){
return new ResponseEntity<User>(p, HttpStatus.OK);
}
}
throw new IllegalArgumentException("Password or email incorrect");
}
Similarly, I would like to @ResponseBodyreturn a minimized version of the User object, where, for example, the password is excluded.
? "json-view"? REST python, , . ?