Deepak
Deepak

Reputation: 1042

How to match codec in cassandra for list<varchar> <-> java.util.List

I have a column info map<text, frozen<list<text>>> in cassandra. Trying to retrieve this map data in java from the below code.

for (Row row : conn.getSession().execute("SELECT info FROM demo.variants where chr = '" +chr + "' and pos = " + pos)) {
    Map<String, List> map = row.getMap("info", String.class, List.class);
    System.out.println(map);
}

When doing this way, I am getting the error

com.datastax.driver.core.exceptions.CodecNotFoundException: Codec not found for requested operation: [list<varchar> <-> java.util.List]

I could not figure out how to resolve this nested type codec exception. What are the ways to resolve this?

Upvotes: 1

Views: 2188

Answers (1)

Andy Tolbert
Andy Tolbert

Reputation: 11638

I would recommend using the TypeTokens.listOf(TypeToken) utility method to create a TypeToken<List<String>> and use that as the element type to retrieve the map, i.e.:

Map<String, List<String>> info = row.getMap("info", TypeToken.of(String.class), TypeTokens.listOf(String.class));

Upvotes: 4

Related Questions