我试图将gov.nist.javax.sip.stack.SIPDialog对象序列化和反序列化到Cassandra中。但是,当我将反序列化对象与我序列化的原始SIPDialog对象进行比较时,该对象上的equals比较失败。所以看起来我在序列化中遗漏了一些东西。我使用ByteArraySerializer将字节读/写到Cassandra。
//保存对话框
MutationBatch mutationBatch = createMutator();
byte[] dialogBytes = SIPDialogEntity.serializeDialog(dialog);
mutationBatch.withRow(SIPDIALOGS, dialogId)
.putColumn("dialog".getBytes(),dialogBytes,null);
mutationBatch.execute();
public static byte[] serializeDialog(SIPDialog dialog) throws IOException {
ByteArrayOutputStream bStream = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bStream);
oos.writeObject(dialog);
oos.close();
byte[] bytes = bStream.toByteArray();
bStream.close();
return bytes;
} //阅读对话框
Column<byte[]> result;
result = getKeySpace().prepareQuery(SIPDIALOGS).getKey(dialogId).getColumn("dialog").execute().getResult();
sipDialog = SIPDialogEntity.deserializeDialog(result.getByteArrayValue());
public static SIPDialog deserializeDialog(byte[] byteArrayDialog) throws IOException, ClassNotFoundException {
System.out.println("DEBUG Reading Dialog Bytes:" + byteArrayDialog );
ByteArrayInputStream bStream = new ByteArrayInputStream(byteArrayDialog);
ObjectInputStream ois = new ObjectInputStream(bStream);
SIPDialog dialog = (SIPDialog) ois.readObject();
ois.close();
bStream.close();
return dialog;
} 发布于 2012-10-19 17:26:40
SIPDialog类没有覆盖equals方法,这就是比较失败的原因。请在http://java.net/jira/browse/JSIP的jain sip中打开一个问题
发布于 2012-10-18 21:36:25
嗯,如果SipDialog是你的类,你可以跳过所有的工作,使用PlayOrm ;)。这样你就不需要处理序列化/反序列化了。
如果它不是你的类,我想我会让他们添加一种方法来添加第三方beans,将其转换为实体,就像Guice在绑定文件中所做的那样,这样它就可以绑定到可以由PlayOrm保存的实体。如果你在PlayOrm上申请了一个工单,我们可能在短短一周内就能得到这个功能。
https://stackoverflow.com/questions/12941092
复制相似问题