title: Spark Scala Programming for not serializable objects and functions
body: <p>I have a "Task not serializable" Exception when I run a Spark Scala program with</p>
  
  <ul>
  <li>Spark RDDs is of not serializable type (java class)</li>
  <li>called functions are from a not serializable class (java class, again)</li>
  </ul>
  
  <p>my code is something like this</p>
  
  <pre><code>object Main{
      def main(args : Array(String){
          ...
          var rdd = sc.textFile(filename)
                    .map(line =&gt; new NotSerializableJClass(line)).cache() 
          //rdd is RDD[NotSerializableJClass]
          ...
          var test = new NotSerializableJPredicate()
          rdd = rdd.filter(elem =&gt; test.test(elem))
          //throws TaskNotSerializable on test Predicate class
      }
  }
  </code></pre>
  
  <p>I notice that i can resolve the second part with</p>
  
  <pre><code>rdd = rdd.filter(elem =&gt; (new NotSerializableJPredicate()).test(elem))
  </code></pre>
  
  <p>but I still get that Exception for the class of the objects in RDDs. And I would in another way also the second part in another way just because I don't want to create a great number of PredicateClass's object.</p>
  
  <p>Can you help me? How can I go forward with non-serializable class?</p>