title: Restrict JSON attributes for @RequestBody
body: <p>This may be a simple task, but I couldn't find a way to do it. Basically, I need to disallow some parameters at the time of using <code>@RequestBody</code> annotation in my controller.</p>
  
  <p>Here is my model:</p>
  
  <pre><code>@Data
  public class MyModel {
    private int id;
    private String name;
  }
  </code></pre>
  
  <p>What I want to do is at the time of response, I want both of the properties to be serialized to JSON, but at the time of create or update, I prefer not to receive <code>id</code> as part of <code>@RequestBody</code> deserialization.</p>
  
  <p>Right now, if I pass <code>id</code> in the JSON body, Spring initializes a <code>MyModel</code> object with its <code>id</code> set to the passed value.</p>
  
  <p>Reason? The ID cannot be generated until the model is created, so the app shouldn't allow the ID to be set. On update, the ID needs to be passed in the URL itself e.g. (<code>PUT /mymodels/43</code>). This helps following the REST principles appropriately.</p>
  
  <p>So, is there any way to achieve this functionality?</p>
  
  <hr>
  
  <p><strong>Update 1:</strong></p>
  
  <p>Right now, I am stuck with using a request wrapper. I created a new class <code>MyModelRequestWrapper</code> with only <code>name</code> as its property, and have used it with the <code>@RequestBody</code> annotation.</p>