title: @ResponseBody , ResponseEntity Spring return Object as JSON
body: <p>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:</p>
  
  <pre><code>@RequestMapping(value = "/resources/users", method = RequestMethod.GET)
  public ResponseEntity&lt;User&gt; 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&lt;User&gt;(user, userStatus);
  }
  </code></pre>
  
  <p>can any body explain ? is ResponseBody/ResponseEntity do the work itself ? when I need to annotate the object class to be returned as JSON.</p>