Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java kryo列表序列化_Java_List_Serialization_Constructor_Kryo - Fatal编程技术网

Java kryo列表序列化

Java kryo列表序列化,java,list,serialization,constructor,kryo,Java,List,Serialization,Constructor,Kryo,我正在尝试使用Kryo序列化一些对象的列表(自定义类:List>) list2D; // List<List<MyClass>> which is already produced. Kryo k1 = new Kryo(); Output output = new Output(new FileOutputStream("filename.ser")); k1.writeObject(output, (List<List<Myclass>>)

我正在尝试使用Kryo序列化一些对象的列表(自定义类:List>)

list2D; // List<List<MyClass>> which is already produced.

Kryo k1 = new Kryo();
Output output = new Output(new FileOutputStream("filename.ser"));
k1.writeObject(output, (List<List<Myclass>>) list2D);
output.close();

我怎样才能解决这个问题

根据您的错误,您可能希望向类中添加无参数构造函数:

 public class MyClass {

    public MyClass() {  // no-arg constructor

    }

    //Rest of your class..

 }

读回对象时不能使用
List.class
,因为
List
是一个接口

k2.readObject(listRead,  ArrayList.class);

谢谢你的回答。但是MyClass已经有了一个接受一个字符串参数的构造函数。有什么想法吗?添加零参数构造函数或编写自己的序列化程序来创建对象。您可以扩展FieldSerializer并覆盖create。您解决了这个问题吗?您是对的。我们不需要投。Ie:
List data=kryo.readObject(输入,ArrayList.class)
 public class MyClass {

    public MyClass() {  // no-arg constructor

    }

    //Rest of your class..

 }
k2.readObject(listRead,  ArrayList.class);