title: Spring @Requestbody not mapping to inner class
body: <p>I am doing Spring Rest Api project with Spring 4.x</p>
  
  <p><strong>This Works:</strong></p>
  
  <p><em>Controller.java</em></p>
  
  <pre><code>@PostMapping("newTransaction")
  TransactionRequestModel insertNewTransaction(@RequestBody TransactionRequestModel model){
      //do something
  }
  </code></pre>
  
  <p><em>TransactionRequestModel.java</em></p>
  
  <pre><code>public class TransactionRequestModel {
      private int id;
      private List&lt;KeyValue&gt; keyValueList;
      public TransactionRequestModel(){}
      //default constructor
      //getter-setter 
  }
  </code></pre>
  
  <p><em>KeyValue.java</em></p>
  
  <pre><code>public class KeyValue {
  
      String key;
      String value;
      //default constructor
      //setter-getter
  }
  </code></pre>
  
  <p><em>Request Body Json</em></p>
  
  <pre><code>{
    "id": 1 
    "keyValueList": [
      {
        "key": "dummy",
        "value": "dummy"
      }
    ]
  }
  </code></pre>
  
  <p>Spring message converter using jackson is working fine.</p>
  
  <p><strong>This Won't:</strong></p>
  
  <p>When i change <em>TransactionRequestModel.java</em> to following (and delete <em>KeyValue.java</em>)</p>
  
  <pre><code>public class TransactionRequestModel {
  
      public class KeyValue {     
        String key;
        String value;
        //default constructor
        //setter-getter
      }
      private int id;
      private List&lt;KeyValue&gt; keyValueList;
      public TransactionRequestModel(){}
      //default constructor
      //getter-setter 
  }
  </code></pre>
  
  <p>means, making <em>KeyValue</em> an <strong>inner class</strong>, got following error.</p>
  
  <blockquote>
    <p>org.springframework.http.converter.HttpMessageNotReadableException:
    Could not read document: No suitable constructor found for type
    [simple type, class
    com.example.model.TransactionRequestModel$KeyValue]: can not
    instantiate from JSON object (missing default constructor or creator,
    or perhaps need to add/enable type information?)</p>
  </blockquote>
  
  <p><strong>Why?</strong></p>
  
  <p>All the related post in SO mentions the first scenario. I would like to know why this wont work. Please help.</p>