I have a Cassandra table defined like so:
create table foo (id int primary key, mapofmaps map<text, frozen<map<text, int>>>);
Into which I place some data:
insert into foo (id, mapofmaps) values (1, {'pets'; {'dog'; 42, 'cat'; 7}, 'foods': {'taco': 555, 'cake', '721'}});
I am then trying to use spring-data-cassandra
to interact with it. I have a POJO:
@Table
public class Foo {
@PrimaryKey
private Integer id;
@Column("mapofmaps")
private Map<String, Map<String, Integer>> mapOfMaps;
// getters/setters omitted for brevity
}
And a Repository
:
public interface FooRepository extends CassandraRepository<Foo> {
}
And then the following code to try and retrieve all the records as a simple test:
public Iterable<Foo> getAllFoos() {
return fooRepository.findAll();
}
Unfortunately this throws an exception. Less funky column types work OK, e.g. a List<String>
and non-nested `Map type columns work fine. But this map of maps is not working for me.
Wondering if there is no support for this in spring-data-cassandra
(though the exception appears to be in the DataStax code) or whether I just need to do something different with the POJO.
The exception thrown is as follows:
Caused by: java.lang.NullPointerException: null
at com.datastax.driver.core.TypeCodec$MapCodec.deserialize(TypeCodec.java:821)
at com.datastax.driver.core.TypeCodec$MapCodec.deserialize(TypeCodec.java:775)
at com.datastax.driver.core.ArrayBackedRow.getMap(ArrayBackedRow.java:299)
at org.springframework.data.cassandra.convert.ColumnReader.get(ColumnReader.java:53)