title: Spring JPA Create ResponseEntity from findById()
body: <p>In a spring boot application, I have an endpoint that returns a HTTP 200 response with an object if it exists, or a HTTP 404 reponse if not. Using spring-boot-starter-parent 1.5.7 I used to do that like this:</p>
  
  <pre><code>@Autowired private GroceryRepository groceryRepository;
  
  @RequestMapping(value = "/get/{id}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
  public ResponseEntity&lt;Object&gt; get(@PathVariable final Integer id) {
      final Grocery grocery = groceryRepository.findOne(id);
      if (null == grocery) {
          return ResponseEntity
                  .status(HttpStatus.NOT_FOUND)
                  .body(MessageUtil.parse(MSG_404_GROCERY, id + ""));
      }
      return ResponseEntity.ok(grocery);
  }
  
  GroceryRepository extends JpaRepository&lt;Grocery, Integer&gt;
  </code></pre>
  
  <p>In spring-boot-starter-parent 2.0.0, <code>findOne()</code> has disappeared from JpaRepository, and <code>findById()</code> returns an <code>Optional</code>. I'm struggling a bit on how to 'port' the above code. The following doesn't build, since it has an unexpected return type:</p>
  
  <pre><code>groceryRepository.findById(id).ifPresent(grocery -&gt; {
      return ResponseEntity.ok(grocery);
  });
  </code></pre>
  
  <p>Can someone tell me what would be the proper way of returning the right Response?</p>
  
  <p>Thanks for any help!</p>