Raw json document with n1ql in java sdk

@asarkar simply use the byteValue method on N1qlQueryRow/AsyncN1qlQueryRow to get the raw bytes and avoid internal deserialization of JSON. Then use your existing JSON deserializer to do that yourself.

For instance, if you just want to print the N1QL rows as Strings to the console:

//assuming we have person data in the default bucket
N1qlQuery query = N1qlQuery.simple("SELECT firstName, lastName FROM default WHERE type = 'person'");
N1qlResult result = bucket.query(query);
for (N1qlQueryRow row : result) {
    //we go straight for the raw bytes and turn into string
    String fullName = new String(row.byteValue());
    //no JsonObject conversion has taken place as long as you don't call "value()"
    System.out.println(fullName);
}
1 Like