我正在尝试迭代JavaRDD<Tuple2<String, Object>>
并使用数据构建JSONArray。
我的代码:
final JSONArray jA = new JSONArray();
final VoidFunction<Tuple2<String, Object>> func = new VoidFunction<Tuple2<String, Object>>() {
@Override
public void call(Tuple2<String, Object> arg0) throws Exception {
JSONObject obj = new JSONObject();
obj.put(columnName, arg0._1);
obj.put("frequency", (String) arg0._2);
jA.put(obj);
}
};
outputRdd.foreach(func);
我收到以下序列化错误(为了便于阅读,删除了完整的跟踪):
org.apache.spark.SparkException: Task not serializable
Caused by: java.io.NotSerializableException: org.json.JSONArray
Serialization stack:
- object not serializable (class: org.json.JSONArray, value: [])
任何指针或解决方法?
谢谢:)