title: why java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to com.readbook.chinesepoetry.data.model.Response？
body: <p>I'm a beginner of kotlin Android developer. I come across this problem and I don't know how to resolve it.</p>
  
  <p>I define a kotlin extension function <code>Observable&lt;T&gt;.toTraditional()</code> in order to keep Rx flow call, but I met an exception.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>class Test {
      @Test
      fun test() {
          val json = "{\"result\":{\"curPage\":1,\"data\":[{\"id\":1,\"name\":\"关雎\",\"dynasty\":\"先秦\",\"poet\":\"佚名\",\"content\":\"钟鼓乐之。\"},{\"id\":1213,\"name\":\"伐檀\",\"dynasty\":\"先秦\",\"poet\":\"佚名\",\"content\":\"钟鼓乐之。\"}],\"pageCount\":388,\"size\":20,\"total\":7756},\"status\":1,\"message\":\"成功\"}"
          Observable.create&lt;Response&lt;RecommendListBean&gt;&gt; {
              val response = getResponse&lt;Response&lt;RecommendListBean&gt;&gt;(json)
              it.onNext(response)
          }.toTraditional().subscribe({},{
              println(it)
          })
      }
  
      inline fun &lt;reified T&gt; getResponse(json: String): T {
          return fromJson(json)
      }
  
      inline fun &lt;reified T&gt; Observable&lt;T&gt;.toTraditional(): Observable&lt;T&gt; {
          return map {
              val toJson = Gson().toJson(it)
              // In fact, I convert simplified chinese in json to traditional chinese.
              // Here, I intentionally omit that code to make my problem more clearly.
              val result = fromJson&lt;T&gt;(toJson)
              result
          }
      }
  
      inline fun &lt;reified T&gt; fromJson(json: String?): T {
          return Gson().fromJson&lt;T&gt;(json, object : TypeToken&lt;T&gt;() {}.type)
      }
  }
  </code></pre>
  
  <p>Also, I need to provide my three beans:</p>
  
  <pre><code>data class Response&lt;T&gt;(
          val message: String,
          @SerializedName(value = "result", alternate = ["data"])
          val result: T,
          val status: Int
  )
  </code></pre>
  
  <pre><code>data class RecommendListBean(
          val curPage: Int,
          val data: List&lt;PoetryBean&gt;,
          val pageCount: Int,
          val size: Int,
          val total: Int
  )
  </code></pre>
  
  <pre><code>data class PoetryBean (
      val content: String,
      val dynasty: String,
      val id: Int,
      val name: String,
      val poet: String
  )
  </code></pre>
  
  <p>After runnint the above code, I get the error:</p>
  
  <blockquote>
    <p>java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to com.readbook.chinesepoetry.data.model.Response</p>
  </blockquote>
  
  <p>I have look up this exception on the internet, many say that it's because kotlin generics erase. But, I exam my code, they really have <code>reified</code> keyword.</p>