title: Getting org.springframework.http.converter.HttpMessageNotWritableException if i search user id which is not present in DB
body: <p>I am building RESTAPI in Spring boot+JPA(MYSQL). If I serach for an user id which is not present in the db, I get below response as error:</p>
  
  <pre><code>{
      "timestamp": 1545657449608,
      "status": 500,
      "error": "Internal Server Error",
      "exception": "**org.springframework.http.converter.HttpMessageNotWritableException**",
      "message": "Could not write content: Unable to find com.bookmyshow.user.User with id asd (through reference chain: com.bookmyshow.user.User_$$_jvst809_0[\"username\"]); nested exception is **com.fasterxml.jackson.databind.JsonMappingException**: Unable to find com.bookmyshow.user.User with id asd (through reference chain: com.bookmyshow.user.User_$$_jvst809_0[\"username\"])",
      "path": "/users/asd"
  }
  </code></pre>
  
  <p><strong>UserRegistrationController</strong></p>
  
  <pre><code>package com.bookmyshow.user;
  
  import java.util.List;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.http.ResponseEntity;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RestController;
  
  @RestController
  public class UserRegistrationController {
  
  @Autowired
  private UserDAO userDAO;
  
  @RequestMapping("/users/{id}") 
  public ResponseEntity&lt;?&gt; getUser(@PathVariable String id) {
  
      User user= userDAO.getUser(id);
  
      if(user==null) {
          return ResponseEntity.notFound().build();
      }
  
      return ResponseEntity.ok().body(user);
      }
  </code></pre>
  
  <p><strong>UserDAO</strong></p>
  
  <pre><code>package com.bookmyshow.user;
  import java.util.List;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  
  
  @Service
  public class UserDAO {
  
  @Autowired
  UserRepository userRepository;  
  
  public User getUser(String id) {
  
       System.out.println("USERDAO:"+id);
            return userRepository.getOne(id);
  }
  </code></pre>