private static void insertJsonColumn ( CqlSession session ) { User alice = new User ( "alice" , 30 ) ; User bob = new User ( "bob" , 35 ) ; // Build and execute a simple statement Statement stmt = insertInto ( "examples" , "json_jackson_column" ) . value ( "id" , literal ( 1 ) ) // the User object will be converted into a String and persisted into the VARCHAR column // "json" . value ( "json" , literal ( alice , session . getContext ( ) . getCodecRegistry ( ) ) ) . build ( ) ; session . execute ( stmt ) ; // The JSON object can be a bound value if the statement is prepared // (subsequent calls to the prepare() method will return cached statement) PreparedStatement pst = session . prepare ( insertInto ( "examples" , "json_jackson_column" ) . value ( "id" , bindMarker ( "id" ) ) . value ( "json" , bindMarker ( "json" ) ) . build ( ) ) ; session . execute ( pst . bind ( ) . setInt ( "id" , 2 ) . set ( "json" , bob , User . class ) ) ; }
Mapping a User instance to a table column