title: Generics problems encountered by Kotlin and GSON
body: <p>I try to write a network request function，Its role is to analyze the general format and provide data content to callbacks.</p>
  
  <p>This is my defined class:
  </p>
  
  <pre><code>data class Response&lt;T&gt;(
      val code: Int = 0,
      @JvmSuppressWildcards
      var data: ArrayList&lt;T&gt;,
      val message: String = "")
  </code></pre>
  
  <p>in this class 'code' and 'message' is fixed，'data' has different types</p>
  
  <p>Select one of data:</p>
  
  <pre><code>data class TestData(
      @SerializedName("create_by")
      val createBy: String = "",
      @SerializedName("create_time")
      val createTime: String = "",
      @SerializedName("name")
      val name: String = "",
      @SerializedName("id")
      val id: String = "")
  </code></pre>
  
  <p>There is my network request function:
  </p>
  
  <pre><code>fun &lt;T&gt; post(callBack: (ArrayList&lt;T&gt;) -&gt; Unit) {
      ...
       override fun onSuccess(response:Response&lt;String&gt;) {
            val result = gson.fromJson&lt;Response&lt;T&gt;&gt;(response.body().reader(),Response::class.java)
            when{
                result.code==200-&gt; callBack.invoke(result.data)
            }
       }
      ...
  }
  </code></pre>
  
  <p>Use it at Activity:
  </p>
  
  <pre><code>Request.addr(Constants.GET_TEST)
         .post&lt;TestData&gt; {
              tv.text = it[0].name
          }
  </code></pre>
  
  <p>When i use Gson parse the server returns data,and want use JavaBean ,Logcat throw this Exception:</p>
  
  <blockquote>
    <p>java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to com.example.network.response.TestData</p>
  </blockquote>
  
  <p>i tried to use TypeToken to solve this problem ，but it also does not work.</p>