title: class com.google.gson.internal.LinkedTreeMap cannot be cast to class Partner
body: <pre><code>import com.google.gson.Gson
  import com.google.gson.reflect.TypeToken
  
  fun main() {
  
      val jsonString: String = """{
          "jsonrpc": "2.0",
          "id": null,
          "result": [
              {
                  "id": 1,
                  "name": "Lekhnath Rijal"
              },
              {
                  "id": 2,
                  "name": "Administrator"
              }
          ]
      }"""
  
      val body1 = Gson().fromJson&lt;RpcResult&lt;List&lt;Partner&gt;&gt;&gt;(jsonString, object: TypeToken&lt;RpcResult&lt;List&lt;Partner&gt;&gt;&gt;(){}.type)
  
      println(body1.result[0].name) // prints Lekhnath Rijal // - As expected
  
      val body2 = fromJson&lt;RpcResult&lt;List&lt;Partner&gt;&gt;&gt;(jsonString)
      println(body2.result[0].name) // throws Exception as stated below after this code snippet
  }
  
  fun &lt;T&gt; fromJson(json: String?): T {
      return Gson().fromJson&lt;T&gt;(json, object: TypeToken&lt;T&gt;(){}.type)
  }
  
  data class RpcResult&lt;T&gt;(
      val jsonrpc: String,
      val id: Int?,
      val result: T
  )
  
  data class Partner(
      val id: Int,
      val name: String
  )
  </code></pre>
  
  <p><strong>Exception</strong>: <code>java.lang.ClassCastException: class com.google.gson.internal.LinkedTreeMap cannot be cast to class RpcResult</code></p>
  
  <p>while converting json string to data class object without using function it works as expected but executing same code from helper function does not work and instead throws an exception mentioned above. What am I missing here?</p>