title: How to persist new JSON object with many-to-one field by its ID?
body: <p>I'm new to Spring Boot and have quite annoying problem.</p>
  
  <p>I have two related entities: Transaction and Category</p>
  
  <p><strong>Category.java</strong></p>
  
  <pre><code>@Data
  @Entity
  @Table(name = "t_categories")
  public class Category extends BaseEntity {
  
    @Column(name = "category_name")
    private String name;
  }
  </code></pre>
  
  <p><strong>Transaction.java</strong></p>
  
  <pre><code>@Data
  @Entity
  @Table(name = "t_transactions")
  public class Transaction extends BaseEntity {
  
    private String description;
  
    @ManyToOne
    @JoinColumn
    private Category category;
  }
  </code></pre>
  
  <p>And when I want to add new category, I simply do POST request with JSON body like this:</p>
  
  <pre><code>{
    "name": "XYZ"
  }
  </code></pre>
  
  <p>And new category is created (e.g. with ID 1). Now I want to add new Transaction with JSON like this:</p>
  
  <pre><code>{
    "description": "Qwerty",
    "category": 1
  }
  </code></pre>
  
  <p>So I want to pass only ID of related object. Following error is thrown:</p>
  
  <pre><code>Cannot construct instance of `persistence.models.Category` (although at least one Creator exists): no int/Int-argument constructor/factory method to deserialize from Number value (1); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `persistence.models.Category` (although at least one Creator exists): no int/Int-argument constructor/factory method to deserialize from Number value (1)\n at [Source: (PushbackInputStream); line: 3, column: 12] (through reference chain: persistence.models.Category[\"parent\"])"
  </code></pre>
  
  <p>What should I do now? Searching this error gives inconclusive information. I'm new to this and it is quite puzzling.</p>