title: How to convert DataFrame to Dataset in Apache Spark in Java?
body: <p>I can convert DataFrame to Dataset in Scala very easy:</p>
  
  <pre><code>case class Person(name:String, age:Long)
  val df = ctx.read.json("/tmp/persons.json")
  val ds = df.as[Person]
  ds.printSchema
  </code></pre>
  
  <p>but in Java version I don't know how to convert Dataframe to Dataset? Any Idea?</p>
  
  <p>my effort is:</p>
  
  <pre><code>DataFrame df = ctx.read().json(logFile);
  Encoder&lt;Person&gt; encoder = new Encoder&lt;&gt;();
  Dataset&lt;Person&gt; ds = new Dataset&lt;Person&gt;(ctx,df.logicalPlan(),encoder);
  ds.printSchema();
  </code></pre>
  
  <p>but the compiler say:</p>
  
  <pre><code>Error:(23, 27) java: org.apache.spark.sql.Encoder is abstract; cannot be instantiated
  </code></pre>
  
  <h2>Edited(Solution):</h2>
  
  <p>solution based on @Leet-Falcon answers:</p>
  
  <pre><code>DataFrame df = ctx.read().json(logFile);
  Encoder&lt;Person&gt; encoder = Encoders.bean(Person.class);
  Dataset&lt;Person&gt; ds = new Dataset&lt;Person&gt;(ctx, df.logicalPlan(), encoder);
  </code></pre>