Serializing/deserializing a SIPDIalog

Serializing/deserializing a SIPDIalog

I was trying to serialize and deserialize a gov.nist.javax.sip.stack.SIPDialog object into Cassandra. But the equals comparison on the deserialized object fails when I compare it with the original SIPDialog object I serialized. SO looks like I am missing something here in serialisation. I am using a ByteArraySerializer to read/write the bytes into Cassandra.
//Saving Dialog
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;
}

//Reading Dialog
Column 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;
}

Solutions/Answers:

Solution 1:

The SIPDialog class doesn’t override the equals method which is why it fails the comparison. Please open an issue in jain sip at http://java.net/jira/browse/JSIP

Solution 2:

hmmmm, If SipDialog is your class, you could just skip all the work and use PlayOrm for cassandra ;). Then you don’t need to deal with serializing/deserializing.

If it is not your class, I think I will get them to add a way to add 3rd party beans to be converted to an entity much like Guice does in a binding file so it can bind to an entity that can be saved by PlayOrm. IF you open a ticket on PlayOrm with a request, we could get the feature in probably in as little as 1 week.

References

Related:  Is it possible to submit a CQL script to a cassandra cluster via the datastax driver?