答案 0 :(得分:0)
您可以为未实现DataSerialisable的类实现Custom Serializer
。
首先,让我们创建一个简单的对象。
public class Employee {
private String surname;
public Employee( String surname ) {
this.surname = surname;
}
}
现在,让我们为Employee类实现StreamSerializer。
public class EmployeeStreamSerializer
implements StreamSerializer<Employee> {
@Override
public int getTypeId () {
return 1;
}
@Override
public void write( ObjectDataOutput out, Employee employee )
throws IOException {
out.writeUTF(employee.getSurname());
}
@Override
public Employee read( ObjectDataInput in )
throws IOException {
String surname = in.readUTF();
return new Employee(surname);
}
@Override
public void destroy () {
}
}
这里有完整的例子: http://docs.hazelcast.org/docs/3.7/manual/html-single/index.html#custom-serialization