list <blob> type column seems to corrupt after the query.

4 views
Skip to first unread message

Eunsu Kim

unread,
Nov 7, 2017, 3:05:18 AM11/7/17
to DataStax Java Driver for Apache Cassandra User Mailing List
My cassandra is 3.11.0

The Java object is serialized into a byte array(by ProtoBuf) and then inserted into the list <blob> column. 

CREATE TABLE keyspace.A (

    name text,

    data list<blob>,

    PRIMARY KEY ...

)


List<ByteBuffer> dataList =...... 

dataList.add(ByteBuffer.wrap(objectArray));


ps.bind().set("name", "aaa", String.class).set("data", dataList, new TypeToken<List<ByteBuffer>>() {} );



It works fine.


However, if we select the table in Cassandra and deserialize the bytebuffer object in the list, the data is corrupted and deserialization is not possible. (parsing error)



TypeToken<List<ByteBuffer>> dataListTypeToken = new TypeToken<List<ByteBuffer>>() {};



rs -> {
List<ByteBuffer> result = new ArrayList<>();
for (Row row : rs) {
List<ByteBuffer> dataList = row.get("data", dataListTypeToken);
result.addAll(dataList);
}
return result;



Do I misunderstand that I deal with Cassandra's list type?


Thank you

Pavani T

unread,
Nov 7, 2017, 3:21:15 AM11/7/17
to java-dri...@lists.datastax.com
HI Eunsu Kim,

Instead of using list collection type use the set type.It may resolve your issue.

Thanks and Regards
pavs

Eunsu Kim

unread,
Nov 7, 2017, 3:28:33 AM11/7/17
to DataStax Java Driver for Apache Cassandra User Mailing List

Than you for your response.
Reply all
Reply to author
Forward
0 new messages