title: Kotlin parcelable and arrayList of parcelables
body: <p>I am trying to write a parcelable data object to pass to from <strong>activityA</strong> to <strong>activityB</strong> in my android application.</p>
  
  <p>My object is passing with all the data, except my <code>arraylist</code> of the class Available Service</p>
  
  <pre><code>data class AvailableService(val id: Int,
                          val name: String,
                          val description: String,
                          val price: Double,
                          val currency: String,
                          val imageUrl: String) : Parcelable {
  
  companion object {
      @JvmField @Suppress("unused")
      val CREATOR = createParcel { AvailableService(it) }
  }
  
  protected constructor(parcelIn: Parcel) : this(parcelIn.readInt(),
          parcelIn.readString(),
          parcelIn.readString(),
          parcelIn.readDouble(),
          parcelIn.readString(),
          parcelIn.readString())
  
  override fun writeToParcel(dest: Parcel?, flags: Int) {
      dest?.writeInt(id)
      dest?.writeString(name)
      dest?.writeString(description)
      dest?.writeDouble(price)
      dest?.writeString(currency)
      dest?.writeString(imageUrl)
  }
  
  override fun describeContents() = 0
  }
  </code></pre>
  
  <p>above is the available <code>serviceClass</code>, next I have Trip, which holds an <code>arraylist</code> of <code>AvailableService</code>.. I observed this in debug, it is successfully writing the <code>arraylist</code>, for some reason I have an issue with reading the data.</p>
  
  <pre><code>data class Trip(val id: String,
              val status: String,
              val orderedServices: ArrayList&lt;OrderedService&gt;) : Parcelable {
  
  companion object {
      @JvmField @Suppress("unused")
      val CREATOR = createParcel { Trip(it) }
  }
  
  protected constructor(parcelIn: Parcel) : this(parcelIn.readString(),
          parcelIn.readString(),
          arrayListOf&lt;OrderedService&gt;().apply {
              parcelIn.readArrayList(OrderedService::class.java.classLoader)
          }
  )
  
  override fun writeToParcel(dest: Parcel?, flags: Int) {
      dest?.writeString(id)
      dest?.writeString(status)
      dest?.writeList(orderedServices)
  }
  
  override fun describeContents() = 0
  }
  </code></pre>
  
  <p>in case someone wonders what's the fun of the CREATOR does, code below:</p>
  
  <pre><code>inline fun &lt;reified T : Parcelable&gt; createParcel(
      crossinline createFromParcel: (Parcel) -&gt; T?): Parcelable.Creator&lt;T&gt; =
      object : Parcelable.Creator&lt;T&gt; {
          override fun createFromParcel(source: Parcel): T? = createFromParcel(source)
          override fun newArray(size: Int): Array&lt;out T?&gt; = arrayOfNulls(size)
      }
  </code></pre>
  
  <p>again, writing succeeds, but reading fails, I get an empty <code>arraylist</code>..
  I think that part is the faulty one:</p>
  
  <pre><code>arrayListOf&lt;OrderedService&gt;().apply {
          parcelIn.readArrayList(OrderedService::class.java.classLoader)
      }
  </code></pre>
  
  <p>is there a different way to read/write <code>arraylist</code>? am I writing it wrong? reading it wrong?</p>
  
  <p>thanks in advance for any help!</p>