title: Jackson: deserialize missing field to Kotlin/Java List
body: <p><sub>I have the answer to my own question, so I post both the answer and solution, as explicitly encouraged by Jeff Atwood. My question was originally for Kotlin, but while trying to find a solution, I also tried Java, so I provide the question and solution in both Java and Kotlin.)</sub></p>
  <h1>Question in Kotlin</h1>
  <p>Given this deserializable <code>Product</code> class:</p>
  <pre><code>data class Product(val name: String, val prices: List&lt;Int&gt;)
  </code></pre>
  <p>and this json string that lacks the <code>prices</code> field:</p>
  <pre><code>{&quot;name&quot;: &quot;Computer&quot;}
  </code></pre>
  <p>how can I deserialize the json string to a <code>Product</code> object using Jackson?</p>
  <h1>What I have tried in Kotlin</h1>
  <p>I tried this:</p>
  <pre><code>data class Product(val name: String, val prices: List&lt;Int&gt;)
  
  // Missing &quot;prices&quot; field
  val json = &quot;&quot;&quot;{&quot;name&quot;: &quot;Computer&quot;}&quot;&quot;&quot;
  
  // &quot;prices&quot; field included works fine
  // val json = &quot;&quot;&quot;{&quot;name&quot;: &quot;Computer&quot;, &quot;prices&quot;: [1,2,3]}&quot;&quot;&quot;
  
  val mapper = ObjectMapper().registerKotlinModule()
  val product = mapper.readValue&lt;Product&gt;(json)
  println(product)
  </code></pre>
  <p>but it results in this exception:</p>
  <pre><code>com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException: Instantiation of 
  [simple type, class MainKt$main$Product] value failed for JSON property prices due to 
  missing (therefore NULL) value for creator parameter prices which is a non-nullable type
   at [Source: (String)&quot;{&quot;name&quot;: &quot;Computer&quot;}&quot;; line: 1, column: 20] 
  (through reference chain: MainKt$main$Product[&quot;prices&quot;])
  </code></pre>
  <h1>When using Java</h1>
  <p>For Java the <code>Product</code> class would be:</p>
  <pre><code>class Product {
      private String name;
      private List&lt;Integer&gt; prices;
  
      public Product(String name, List&lt;Integer&gt; prices) {
          this.name = name;
          this.prices = prices;
      }
  
      @Override
      public String toString() {
          return &quot;Product{name='&quot; + name + &quot;\&quot;, prices=&quot; + prices + '}';
      }
  }
  </code></pre>
  <p>with this Jackson code:</p>
  <pre><code>String json = &quot;{\&quot;name\&quot;: \&quot;Computer\&quot;}&quot;;
  // String json = &quot;{\&quot;name\&quot;: \&quot;Computer\&quot;, \&quot;prices\&quot;: [1,2,3]}&quot;;
  
  ObjectMapper mapper = new ObjectMapper();
  // ParameterNamesModule is needed for non-arg constructor when not using Jackson annotations
  mapper.registerModule(new ParameterNamesModule());
  Product product = mapper.readValue(json, Product.class);
  
  // Shows &quot;prices=null&quot;, while &quot;prices=[]&quot; is required
  System.out.println(product);
  </code></pre>
  <p>But this sets <code>prices</code> to <code>null</code> instead of an empty list.</p>