title: How to serialize ArrayList of Pair using gson
body: <p>I am trying to deserialize an object of type </p>
  
  <p><code>ArrayList&lt;Pair&lt;OuterData, ArrayList&lt;InnerData&gt;&gt;&gt;</code></p>
  
  <p>where <code>OuterData</code> and <code>InnerData</code> are POJOs using gson.</p>
  
  <p>I have tried so hard but I'm not able to do it. I am getting </p>
  
  <blockquote>
    <p>java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap
    cannot be cast to
    v2015.oasis.pilani.bits.com.home.events.inner.InnerData</p>
  </blockquote>
  
  <p>whenever I try to do <code>new Gson().fromJson(json, type);</code></p>
  
  <p>where type is obtained from TypeToken using </p>
  
  <pre><code>new TypeToken&lt;ArrayList&lt;Pair&lt;OuterData, ArrayList&lt;InnerData&gt;&gt;&gt;&gt;(){}.getType()
  </code></pre>
  
  <p>I though using Type will solve my problem as initially I want't using it but it didn't. Any help is appreciated.</p>
  
  <p>Edit: Here are the <code>OuterData</code> and <code>InnerData</code> classes (In kotlin)</p>
  
  <pre><code>data class InnerData(val name: String,
                       val category: String,
                       val categoryIcon: Int,
                       val description: String,
                       val rules: String,
                       val time: String,
                       val date: String,
                       val venue: String,
                       val notifyState: Boolean,
                       val notifyTime: Int,
                       val favouriteState: Boolean)
  
  data class OuterData(val heading: String, val color: Int)
  </code></pre>
  
  <p>I am using gson only to serialize the data. So deserialization is using the same json serialized using gson. </p>
  
  <p>Edit2 : Serialized JSON Data: It was the output serialization using gson</p>
  
  <pre><code>[
  {
      "first": {
          "color": -65281,
          "heading": "October 01"
      },
      "second": [
          {
              "category": "",
              "categoryIcon": 17301533,
              "date": "",
              "description": "sfd",
              "favouriteState": false,
              "name": "sdfds",
              "notifyState": false,
              "notifyTime": 0,
              "rules": "",
              "time": "",
              "venue": ""
          }
      ]
  },
  {
      "first": {
          "color": -65281,
          "heading": "November 01"
      },
      "second": [
          {
              "category": "",
              "categoryIcon": 17301533,
              "date": "djfkd",
              "description": "klddjflk",
              "favouriteState": false,
              "name": "jkl",
              "notifyState": false,
              "notifyTime": 0,
              "rules": "",
              "time": "sdkjfk",
              "venue": "ldkfjf"
          }
      ]
  },
  {
      "first": {
          "color": -16175867,
          "heading": "October 31"
      },
      "second": [
          {
              "category": "Event Category",
              "categoryIcon": 17301533,
              "date": "31-10-2017",
              "description": "Event Description",
              "favouriteState": false,
              "name": "Event name",
              "notifyState": false,
              "notifyTime": 0,
              "rules": "Events Rules",
              "time": "13:55",
              "venue": "Event Venue"
          },
          {
              "category": "",
              "categoryIcon": 17301533,
              "date": "",
              "description": "",
              "favouriteState": false,
              "name": "dsf",
              "notifyState": false,
              "notifyTime": 0,
              "rules": "",
              "time": "",
              "venue": ""
          },
          {
              "category": "",
              "categoryIcon": 17301533,
              "date": "",
              "description": "",
              "favouriteState": false,
              "name": "",
              "notifyState": false,
              "notifyTime": 0,
              "rules": "",
              "time": "",
              "venue": ""
          },
          {
              "category": "",
              "categoryIcon": 17301533,
              "date": "",
              "description": "",
              "favouriteState": false,
              "name": "",
              "notifyState": false,
              "notifyTime": 0,
              "rules": "",
              "time": "",
              "venue": ""
          },
          {
              "category": "",
              "categoryIcon": 17301533,
              "date": "",
              "description": "",
              "favouriteState": false,
              "name": "",
              "notifyState": false,
              "notifyTime": 0,
              "rules": "",
              "time": "",
              "venue": ""
          },
          {
              "category": "",
              "categoryIcon": 17301533,
              "date": "",
              "description": "",
              "favouriteState": false,
              "name": "",
              "notifyState": false,
              "notifyTime": 0,
              "rules": "",
              "time": "",
              "venue": ""
          },
          {
              "category": "",
              "categoryIcon": 17301533,
              "date": "",
              "description": "",
              "favouriteState": false,
              "name": "",
              "notifyState": false,
              "notifyTime": 0,
              "rules": "",
              "time": "",
              "venue": ""
          },
          {
              "category": "",
              "categoryIcon": 17301533,
              "date": "",
              "description": "",
              "favouriteState": false,
              "name": "",
              "notifyState": false,
              "notifyTime": 0,
              "rules": "",
              "time": "",
              "venue": ""
          },
          {
              "category": "",
              "categoryIcon": 17301533,
              "date": "",
              "description": "",
              "favouriteState": false,
              "name": "",
              "notifyState": false,
              "notifyTime": 0,
              "rules": "",
              "time": "",
              "venue": ""
          }
      ]
  }]
  </code></pre>