title: Spark java : Creating a new Dataset with a given schema
body: <p>I have this code that is working well in scala : </p>
  
  <pre><code>val schema = StructType(Array(
          StructField("field1", StringType, true),
          StructField("field2", TimestampType, true),
          StructField("field3", DoubleType, true),
          StructField("field4", StringType, true),
          StructField("field5", StringType, true)
      ))
  
  val df = spark.read
      // some options
      .schema(schema)
      .load(myEndpoint)
  </code></pre>
  
  <p>I want to do something similar in Java. So my code is the following : </p>
  
  <pre><code>final StructType schema = new StructType(new StructField[] {
       new StructField("field1",  new StringType(), true,new Metadata()),
       new StructField("field2", new TimestampType(), true,new Metadata()),
       new StructField("field3", new StringType(), true,new Metadata()),
       new StructField("field4", new StringType(), true,new Metadata()),
       new StructField("field5", new StringType(), true,new Metadata())
  });
  
  Dataset&lt;Row&gt; df = spark.read()
      // some options
      .schema(schema)
      .load(myEndpoint);
  </code></pre>
  
  <p>But this give me the following error : </p>
  
  <pre><code>Exception in thread "main" scala.MatchError: org.apache.spark.sql.types.StringType@37c5b8e8 (of class org.apache.spark.sql.types.StringType)
  </code></pre>
  
  <p>Nothing seem wrong with my schemas so I don't really know what the problem is here.</p>
  
  <pre><code>spark.read().load(myEndpoint).printSchema();
  root
   |-- field5: string (nullable = true)
   |-- field2: timestamp (nullable = true)
   |-- field1: string (nullable = true)
   |-- field4: string (nullable = true)
   |-- field3: string (nullable = true)
  
  schema.printTreeString();
  root
   |-- field1: string (nullable = true)
   |-- field2: timestamp (nullable = true)
   |-- field3: string (nullable = true)
   |-- field4: string (nullable = true)
   |-- field5: string (nullable = true)
  </code></pre>
  
  <p>EDIT : </p>
  
  <p>Here is a data sample : </p>
  
  <pre><code>spark.read().load(myEndpoint).show(false);
  +---------------------------------------------------------------+-------------------+-------------+--------------+---------+
  |field5                                                         |field2             |field1       |field4        |field3   |
  +---------------------------------------------------------------+-------------------+-------------+--------------+---------+
  |{"fieldA":"AAA","fieldB":"BBB","fieldC":"CCC","fieldD":"DDD"}  |2018-01-20 16:54:50|SOME_VALUE   |SOME_VALUE    |0.0      |
  |{"fieldA":"AAA","fieldB":"BBB","fieldC":"CCC","fieldD":"DDD"}  |2018-01-20 16:58:50|SOME_VALUE   |SOME_VALUE    |50.0     |
  |{"fieldA":"AAA","fieldB":"BBB","fieldC":"CCC","fieldD":"DDD"}  |2018-01-20 17:00:50|SOME_VALUE   |SOME_VALUE    |20.0     |
  |{"fieldA":"AAA","fieldB":"BBB","fieldC":"CCC","fieldD":"DDD"}  |2018-01-20 18:04:50|SOME_VALUE   |SOME_VALUE    |10.0     |
   ...
  +---------------------------------------------------------------+-------------------+-------------+--------------+---------+
  </code></pre>