I'm using Spring version 4 ( spring data), I want to return Object as JSON , I wonderd that the following code worked even without annotating the user class wtih xmlRootElement:
@RequestMapping(value = "/resources/users", method = RequestMethod.GET)
public ResponseEntity<User> getUserByLogonId(OAuth2Authentication auth) {
String userLogonId = ((org.springframework.security.core.userdetails.User) auth.getUserAuthentication()
.getPrincipal()).getUsername();
UsersServices usersServices = new UsersServicesImpl(usersOperations);
User user = usersServices.findByLogonId(userLogonId);
HttpStatus userStatus = HttpStatus.NOT_FOUND;
if (user != null) {
userStatus = HttpStatus.FOUND;
}
return new ResponseEntity<User>(user, userStatus);
}
can any body explain ? is ResponseBody/ResponseEntity do the work itself ? when I need to annotate the object class to be returned as JSON.