title: Convert @RequestBody attribute containing entity ID to corresponding entity in Spring
body: <p>Please, is it possible to achieve automatic conversion of request body attribute containing entity ID to corresponding JPA entity?</p>
  
  <pre><code>@Entity
  public class Foo {
      @Id
      private Long id;
  
      // getters and setters
  }  
  
  public class Bar {
      private Foo foo;
  
      // getters and setters
  }
  
  @Controller
  public class Controller {
  
      @RequestMapping(path="/foo", method=RequestMethod.POST)
      public void convertFooAction(@RequestBody Bar bar) {
          // variable bar with foo attribute containing entity with corresponding ID
      }
  }
  </code></pre>
  
  <p>Example JSON request body used in POST request:</p>
  
  <pre><code>{ "foo": 1 }
  </code></pre>
  
  <p>It should work in every case, whether the <code>@RequestBody</code> class is  <code>@Entity</code> or not.</p>
  
  <p>Thanks for any advice.</p>