title: Scala + Spark - How to cast from 'scala.collection.mutable.WrappedArray$ofRef' to our custom object?
body: <p>We are using <code>spark</code> along with <code>Scala</code> in our project.</p>
  <p>We are using custom <code>encoders</code> to create <code>spark datasets</code>.</p>
  <p>Our dataset schema is of type as below:</p>
  <pre><code>(String, util.ArrayList[MyObject])
  </code></pre>
  <p>When  we do df.printSchema, we get following:</p>
  <pre><code>root
   |-- key: string (nullable = true)
   |-- listOfMyObject: array (nullable = true)
   |    |-- element: binary (containsNull = true)
  </code></pre>
  <p>MyObject is scala case class as below:</p>
  <pre><code>case class MyObject(key: String, dataList: java.util.ArrayList[MyObject2])
  </code></pre>
  <p>When we apply map function on this dataframe,</p>
  <pre><code>df.map((row) =&gt; {
  val key  = row.get(0)
  val values = row.get(1)
  })
  </code></pre>
  <p>At runtime, row contains following schema:</p>
  <pre><code>StructField(key,StringType,true)
  StructField(myObject,ArrayType(BinaryType,true),true)
  </code></pre>
  <p>We are able to retrieve the <code>String</code> value, but when trying to retrieve the <code>util.ArrayList[MyObject]</code>, we are getting <code>scala.collection.mutable.WrappedArray$ofRef</code>.</p>
  <p>We got this by using <code>ref.getClass</code> method.</p>
  <p>Any pointers to solve this issue?</p>
  <p>Thanks</p>
  <p>Anuj</p>