You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by S G <sg...@gmail.com> on 2017/03/23 17:08:30 UTC

Using datastax driver, how can I read a non-primitive column as a JSON string?

Hi,

I have several non-primitive columns in my cassandra tables.
Some of them are user-defined-types UDTs.

While querying them through datastax driver, I want to convert such UDTs
into JSON values.
More specifically, I want to get JSON string for the value object below:

            Row row = itr.next();

            ColumnDefinitions cds = row.getColumnDefinitions();

            cds.asList().forEach((ColumnDefinitions.Definition cd) -> {

                String name = cd.getName();

                Object value = row.getObject(name);

          }

I have gone through
http://docs.datastax.com/en/developer/java-driver/3.1/manual/custom_codecs/

But I do not want to add a codec for every UDT I have.


Can the driver somehow return me direct JSON without explicit meddling with
codecs and all?


Thanks

SG

Re: Using datastax driver, how can I read a non-primitive column as a JSON string?

Posted by Vladimir Yudovin <vl...@winguzone.com>.
Hi,



why not used SELECT JSON * FROM as described here https://www.datastax.com/dev/blog/whats-new-in-cassandra-2-2-json-support ?



Best regards, Vladimir Yudovin, 

Winguzone - Cloud Cassandra Hosting






---- On Thu, 23 Mar 2017 13:08:30 -0400 S G &lt;sg.online.email@gmail.com&gt; wrote ----




Hi,



I have several non-primitive columns in my cassandra tables.

Some of them are user-defined-types UDTs.



While querying them through datastax driver, I want to convert such UDTs into JSON values.

More specifically, I want to get JSON string for the value object below:

            Row row = itr.next();

            ColumnDefinitions cds = row.getColumnDefinitions();

            cds.asList().forEach((ColumnDefinitions.Definition cd) -&gt; {

                String name = cd.getName();

                Object value = row.getObject(name);

          }

I have gone through http://docs.datastax.com/en/developer/java-driver/3.1/manual/custom_codecs/

But I do not want to add a codec for every UDT I have.



Can the driver somehow return me direct JSON without explicit meddling with codecs and all?



Thanks

SG