title: How to convert Array[String] into proper schema?
body: <p>I am facing a weird issue while trying to dinamically convert the fields from a <code>RDD[Array[String]]</code> to the proper values specified in a schema for the conversion to a Spark SQL <code>DataFrame</code>.</p>
  
  <p>I have a <code>RDD[Array[String]]</code> and a <code>StructType</code> called <code>schema</code> which specifies the types for the serveral fields. What I have done so far is:</p>
  
  <pre><code>sqlContext.createDataFrame(
      inputLines.map( rowValues =&gt; 
                            RowFactory.create(rowValues.zip(schema.toSeq)
                                                       .map{ case (value, struct) =&gt; 
                                                    struct.dataType match {
                                                      case BinaryType =&gt; value.toCharArray().map(ch =&gt; ch.toByte)
                                                      case ByteType =&gt; value.toByte
                                                      case BooleanType =&gt; value.toBoolean
                                                      case DoubleType =&gt; value.toDouble
                                                      case FloatType =&gt; value.toFloat
                                                      case ShortType =&gt; value.toShort
                                                      case DateType =&gt; value
                                                      case IntegerType =&gt; value.toInt
                                                      case LongType =&gt; value.toLong
                                                      case _ =&gt; value
                                                    }
                                                 })), schema)
  </code></pre>
  
  <p>but I'm getting this Exception:</p>
  
  <pre><code>java.lang.RuntimeException: Failed to convert value [Ljava.lang.Object;@6e9ffad1 (class of class [Ljava.lang.Object;}) with the type of IntegerType to JSON
  </code></pre>
  
  <p>when calling the <code>toJSON</code> method...</p>
  
  <p>Do you have any idea about the reason why this is happening and what could I do to fix it?</p>
  
  <p>As asked, here we have an example:</p>
  
  <pre><code>val schema = StructType(Seq(StructField("id",IntegerType),StructField("val",StringType)))
  val inputLines=sc.parallelize(
        Array("1","This is a line for testing"), 
        Array("2","The second line"))
  </code></pre>