[JCBC-125] Don't cast view documents to strings Created: 03/Oct/12  Updated: 03/Dec/12  Resolved: 08/Nov/12

Status: Resolved
Project: Couchbase Java Client
Component/s: Core
Affects Version/s: 1.1-dp4
Fix Version/s: 1.1-beta
Security Level: Public

Type: Bug Priority: Critical
Reporter: Michael Nitschinger Assignee: Michael Nitschinger
Resolution: Fixed Votes: 0
Labels: view
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment: All

When objects are stored as non-strings in Couchbase and then loaded through a View, the SDK currently casts every document to a string. This works fine for JSON documents, but as soon as you want to store serialized objects it breaks.

Implicit casting is not needed in this place (see fix).

Comment by Michael Nitschinger [ 03/Oct/12 ]
Here is a quick sample on how to reproduce it, but I'm adding a correct test case to the code as well (the view used is just the default "emit key and null" view with no reduce).

import com.couchbase.client.CouchbaseClient;
import com.couchbase.client.CouchbaseConnectionFactory;
import com.couchbase.client.protocol.views.Query;
import com.couchbase.client.protocol.views.View;
import com.couchbase.client.protocol.views.ViewResponse;
import com.couchbase.client.protocol.views.ViewRow;
import java.io.IOException;
import java.net.URI;
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;

public class BinaryviewTest {

   * @param args the command line arguments
  public static void main(String[] args) throws IOException {

    // Initialize Connection
    CouchbaseClient cb = new CouchbaseClient(
      new CouchbaseConnectionFactory(

    // Store binary objects
    Object ob1 = new Date();
    cb.set("date1", 0, ob1);

    Object result = cb.get("date1");

    Query query = new Query();
    View view = cb.getView("testing", "binary");
    ViewResponse response = cb.query(view, query);

    Iterator<ViewRow> iterator = response.iterator();
    ViewRow row;
    while(iterator.hasNext()) {
      row = iterator.next();
      Object obj = row.getDocument();

When run two times, this raises the exception as described here: http://www.couchbase.com/forums/thread/couchbase-2-view-non-json-docs

I'll update it when I have the fix and test ready.
Comment by Michael Nitschinger [ 03/Oct/12 ]
See http://review.couchbase.com/#/c/21305/
Comment by Michael Nitschinger [ 08/Nov/12 ]
pushed to master, will be available in dp5.

Generated at Sat Oct 25 23:06:27 CDT 2014 using JIRA 5.2.4#845-sha1:c9f4cc41abe72fb236945343a1f485c2c844dac9.