title: Spark and Not Serializable DateTimeFormatter
body: <p>I'm trying to use the DateTimeFormatter from java.time.format in Spark but it appears to be not serializable. This is the relevant chunk of code:</p>
  
  <pre><code>val pattern = "&lt;some pattern&gt;".r
  val dtFormatter = DateTimeFormatter.ofPattern("&lt;some non-ISO pattern&gt;")
  
  val logs = sc.wholeTextFiles(path)
  
  val entries = logs.flatMap(fileContent =&gt; {
      val file = fileContent._1
      val content = fileContent._2
      content.split("\\r?\\n").map(line =&gt; line match {
        case pattern(dt, ev, seq) =&gt; Some(LogEntry(LocalDateTime.parse(dt, dtFormatter), ev, seq.toInt))
        case _ =&gt; logger.error(s"Cannot parse $file: $line"); None
      })
    })
  </code></pre>
  
  <p>How can I avoid the <code>java.io.NotSerializableException: java.time.format.DateTimeFormatter</code> exception? Is there a better library to parse timestamps? I've read that Joda is also not serializable and has been incorporated in Java 8's time library.</p>