java—如何序列化avro生成的实体类型的对象列表

tcbh2hod  于 2021-05-27  发布在  Spark
关注(0)|答案(0)|浏览(251)

我尝试执行以下代码时出现序列化错误

public Result implements Serializable {
    ArrayList<AvroGeneratedEntity> entities;
    Map<Integer, String> stringMap;
}

public SomeBo {
    public void aMethod () {
        ......
        JavaRdd<Result> resultJavaRDD = rdd.map(f -> {
        });
        resultJavaRDD.repartition(1).collect();     // Error throws
        ......
    }
}

根据错误消息,这是因为avrogeneratedentity不可序列化

Serialization stack:
    - object not serializable (class: com.testing.AvroGeneratedEntity, value: 
    .....

- field (class: com.testing.AvroGeneratedEntity, name: entities, type: class java.util.ArrayList)
    - object (class com.testing.AvroGeneratedEntity, com.testing.AvroGeneratedEntity@390fcb0c)
    at org.apache.spark.serializer.SerializationDebugger$.improveException(SerializationDebugger.scala:40)
    at org.apache.spark.serializer.JavaSerializationStream.writeObject(JavaSerializer.scala:47)
    at org.apache.spark.serializer.SerializationStream.writeValue(Serializer.scala:147)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题