rantav/hector — Issue #379: Can't read thrift serialized object from cassandra
Author: vhmolinar
Created: 2012-01-03 20:55:59+00:00
State: open

I want to make a column of BytesType to be cross language readable. So I've implemented a thrift serializer(which extends AbstractSerializer from Hector) in order to persist thrift serialized objects into cassandra column.

It worked very well with inserts, but I couldn't read the objects back from the binary data.

I assume that those inserts worked, because I was able to read it from another csharp code.
Also, I assume that my thrift serializer is working well, because I could serialize and deserialize a TBase object in a simple test without using hector mutators and querys. In other words, I think it is an hector reading issue.

Look my ThriftSerializer code below.

public class ThriftSerializer extends AbstractSerializer {

private TSerializer serializer = new TSerializer( new TBinaryProtocol.Factory() );
private Class type;

public ThriftSerializer( Class type ) {
this.type = type;
}

public ByteBuffer toByteBuffer( T obj ) {
byte[] bytes = null;
try {
bytes = serializer.serialize( obj );
} catch ( TException e ) {
e.printStackTrace();
}
return ByteBuffer.wrap( bytes );
}

@Override
public T fromByteBuffer( ByteBuffer byteBuffer ) {
T result = null;

TDeserializer deserializer = new TDeserializer( new TBinaryProtocol.Factory() );
try {

result = type.newInstance();
deserializer.deserialize( result, byteBuffer.array() );
} catch ( TException e ) {
e.printStackTrace();
} catch ( InstantiationException e ) {
e.printStackTrace();
} catch ( IllegalAccessException e ) {
e.printStackTrace();
}
return result;
}