title: How to pass csv mapped bean class to Dataset
body: <p>I wrote code to read a csv file and map all the columns to a bean class.
  Now, I'm trying to set these values to a Dataset and getting an issue. </p>
  
  <pre><code>7/08/30 16:33:58 WARN TaskSetManager: Lost task 0.0 in stage 0.0 (TID 0, localhost): java.lang.IllegalArgumentException: object is not an instance of declaring class
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  </code></pre>
  
  <p>If I try to set the values manually it works fine</p>
  
  <pre><code>public void run(String t, String u) throws FileNotFoundException {
  
      JavaRDD&lt;String&gt; pairRDD =  sparkContext.textFile("C:/temp/L1_result.csv");
      JavaPairRDD&lt;String,String&gt; rowJavaRDD = pairRDD.mapToPair(new PairFunction&lt;String, String, String&gt;() {
  
          public Tuple2&lt;String,String&gt; call(String rec) throws FileNotFoundException {
              String[] tokens = rec.split(";");
              String[] vals = new String[tokens.length];
              for(int i= 0; i &lt; tokens.length; i++){
                  vals[i] =tokens[i];
              }
  
              return new Tuple2&lt;String, String&gt;(tokens[0], tokens[1]);
          }
      });
  
  
      ColumnPositionMappingStrategy cpm = new ColumnPositionMappingStrategy();
      cpm.setType(funds.class);
      String[] csvcolumns = new String[]{"portfolio_id", "portfolio_code"};
      cpm.setColumnMapping(csvcolumns);
  
      CSVReader csvReader = new CSVReader(new FileReader("C:/temp/L1_result.csv"));
  
      CsvToBean csvtobean = new CsvToBean();
      List csvDataList = csvtobean.parse(cpm, csvReader);
  
      for (Object dataobject : csvDataList) {
          funds fund = (funds) dataobject;
          System.out.println("Portfolio:"+fund.getPortfolio_id()+ " code:"+fund.getPortfolio_code());
      }
  
      /*  funds b0 = new funds();
      b0.setK("k0");
      b0.setSomething("sth0");
      funds b1 = new funds();
      b1.setK("k1");
      b1.setSomething("sth1");
      List&lt;funds&gt; data = new ArrayList&lt;funds&gt;();
      data.add(b0);
      data.add(b1);*/
  
      System.out.println("Portfolio:" + rowJavaRDD.values());
  
  
      //manual set works fine ///
      //  Dataset&lt;Row&gt; fundDf = SQLContext.createDataFrame(data, funds.class);
      Dataset&lt;Row&gt; fundDf = SQLContext.createDataFrame(rowJavaRDD.values(), funds.class);
      fundDf.printSchema();
      fundDf.write().option("mergeschema", true).parquet("C:/test");
  }
  </code></pre>
  
  <p>The line below is giving an issue: using <code>rowJavaRDD.values()</code>: </p>
  
  <pre><code>Dataset&lt;Row&gt; fundDf = SQLContext.createDataFrame(rowJavaRDD.values(), funds.class);
  </code></pre>
  
  <p>what is the resolution to this? whatever values Im column mapping should be passed here, but how this needs to be done. Any idea really helps me.</p>