Get Serializable ArrayList on Intent fragment : <p>On my fragment I want to get <code>ArrayList&lt;Animal&gt;</code>. I have created a newInstance function.</p>

<pre><code>  companion object {
    private val ARG_TITLE = "ARG_TITLE"
    private val ARG_ANIMALS = "ARG_ANIMALS"

    fun newInstance(title: String,animals: ArrayList&lt;Animal&gt;): ExampleFragment{
        val fragment = ExampleFragment()
        val args = Bundle()
        args.putString(ARG_TITLE, title)
        args.putSerializable(ARG_ANIMALS, animals)
        fragment.arguments = args
        return fragment
    }
}
</code></pre>

<p>And on my <code>onCreate()</code> I have this.</p>

<pre><code> private var title: String = ""
lateinit private var animals:ArrayList&lt;Animal&gt;

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    if (arguments != null) {
        title = arguments.getString(ARG_TITLE)
        animals = arguments.getSerializable(ARG_ANIMALS)
    }
}
</code></pre>

<p>But </p>

<blockquote>
  <p>Required: ArrayList  found Serialized!</p>
</blockquote>

<p>Can't cast to ArrayList neither.</p>
