title: single custom deserializer for all objects as their ids or embedded whole objects during POST/PUT
body: <pre><code>@Entity
  public Product {
     @Id
     public int id;
  
     public String name;
  
     @ManyToOne(cascade = {CascadeType.DETACH} )
     Category category
  
     @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.DETACH} )
     Set&lt;Category&gt; secondaryCategories;
  
  
  }
  </code></pre>
  
  <p>and this entity: </p>
  
  <pre><code>@Entity
  public Category {
     @Id
     public int id;
  
     public String name;
  }
  </code></pre>
  
  <p>I would like to be able to send a POST with json</p>
  
  <p><code>{ name: "name", category: 2, secondaryCategories: [3,4,5] }</code> from client-side</p>
  
  <p>and be able to be deserialized like: </p>
  
  <pre><code>{ name: "name", category: {id: 2 }, secondaryCategories: [{id: 3}, {id: 4}, {id: 5}] }
  </code></pre>
  
  <p>in case it was sent as </p>
  
  <pre><code> { name: "name", category: {id: 2 }, secondaryCategories: [{id: 3}, {id: 4}, {id: 5}] }
  </code></pre>
  
  <p>I would like it to still work as now</p>
  
  <p>what kind of annotation and custom deserializer I need? Hopefully the deserializer can work for all possible objects that have id as a property</p>
  
  <p>Thanks!</p>
  
  <p><strong>Edit</strong></p>
  
  <ul>
  <li>See the preferred zafrost's <code>@JsonCreator</code> answer (<a href="https://stackoverflow.com/a/46618366/986160">https://stackoverflow.com/a/46618366/986160</a>)</li>
  <li>See my complete answer (<a href="https://stackoverflow.com/a/46618193/986160">https://stackoverflow.com/a/46618193/986160</a>) for extending <code>StdDeserializer</code> and using default deserialization through <code>ObjectMapper</code></li>
  </ul>