title: Deserialize a Kotlin Data Class with Google HTTP Client
body: <p>I am using Google HTTP Client to make an API request, and I would like the to use the <code>parseAs()</code> method to deserialize the JSON response for me. My model is a Kotlin data class, but the deserializer fails to instantiate my class:</p>
  
  <pre><code>Caused by: java.lang.IllegalArgumentException: unable to create new instance of class com.ippontech.blog.stats.model.GitFile because it has no accessible default constructor
  </code></pre>
  
  <p>Here is my Kotlin data class:</p>
  
  <pre><code>data class GitFile(
          val name: String,
          @SerializedName("download_url") val downloadUrl: String)
  </code></pre>
  
  <p>And the code I use:</p>
  
  <pre><code>val requestFactory = NetHttpTransport().createRequestFactory{
      it.setParser(JsonObjectParser(GsonFactory()))
  }
  
  val request = requestFactory.buildGetRequest(
          GenericUrl("https://api.github.com/repos/ippontech/blog-usa/contents/posts"))
  val type = object : TypeToken&lt;List&lt;GitFile&gt;&gt;() {}.type
  val rawResponse = request.execute().parseAs(type)
  </code></pre>
  
  <p>On the other hand, if I retrieve the response as a string, and then use the Gson parser, it works fine:</p>
  
  <pre><code>val requestFactory = NetHttpTransport().createRequestFactory()
  val request = requestFactory.buildGetRequest(
          GenericUrl("https://api.github.com/repos/ippontech/blog-usa/contents/posts"))
  val rawResponse = request.execute().parseAsString()
  val type = object : TypeToken&lt;List&lt;GitFile&gt;&gt;() {}.type
  val gitFiles: List&lt;GitFile&gt; = Gson().fromJson(rawResponse, type)
  </code></pre>
  
  <p>This seems to indicate that <code>JsonObjectParser</code> is not quite doing its job here.</p>
  
  <p>Versions I'm using:</p>
  
  <pre><code>compile 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.30'
  compile 'com.google.code.gson:gson:2.8.0'
  compile 'com.google.apis:google-api-services-sheets:v4-rev512-1.23.0'
  compile 'com.google.api-client:google-api-client-gson:1.23.0'
  </code></pre>
  
  <p>Any idea on how to fix this?</p>