Source:
public <T> List<T> findByView(ViewQuery query, final Class<T> entityClass) { if (!query.isIncludeDocs() || !query.includeDocsTarget().equals(RawJsonDocument.class)) { if (!query.isOrderRetained()) { query.includeDocs(RawJsonDocument.class); } else { query.includeDocsOrdered(RawJsonDocument.class); } } query.reduce(false); return executeAsync(client.async().query(query)) .flatMap(new Func1<AsyncViewResult, Observable<AsyncViewRow>>() { @Override public Observable<AsyncViewRow> call(AsyncViewResult asyncViewResult) { return asyncViewResult .error() .flatMap(new Func1<JsonObject, Observable<AsyncViewRow>>() { @Override public Observable<AsyncViewRow> call(JsonObject error) { return Observable.error(new CouchbaseQueryExecutionException("Unable to execute view query due to the following view error: " + error.toString())); }}) .switchIfEmpty(asyncViewResult.rows()); } }) .flatMap(new Func1<AsyncViewRow, Observable<T>>() { @Override public Observable<T> call(AsyncViewRow row) { final String id = row.id(); return row .document(RawJsonDocument.class) .map(new Func1<RawJsonDocument, T>() { @Override public T call(RawJsonDocument rawJsonDocument) { T entity = mapToEntity(id, rawJsonDocument, entityClass); return entity; } }); }}) .filter(new Func1<T, Boolean>() { @Override public Boolean call(T t) { return t != null; } }) .onErrorResumeNext(new Func1<Throwable, Observable<T>>() { @Override public Observable<T> call(Throwable throwable) { if (throwable instanceof TranscodingException) { return Observable.error(new CouchbaseQueryExecutionException("Unable to execute view query", throwable)); } else { return Observable.error(throwable); } } }) .toList() .toBlocking() .single(); }

Target:
public <T> List<T> findByView(ViewQuery query, final Class<T> entityClass) { if (!query.isIncludeDocs() || !query.includeDocsTarget().equals(RawJsonDocument.class)) { if (query.isOrderRetained()) { query.includeDocsOrdered(RawJsonDocument.class); } else { query.includeDocs(RawJsonDocument.class); } } query.reduce(false); return executeAsync(client.async().query(query)) .flatMap(new Func1<AsyncViewResult, Observable<AsyncViewRow>>() { @Override public Observable<AsyncViewRow> call(AsyncViewResult asyncViewResult) { return asyncViewResult .error() .flatMap(new Func1<JsonObject, Observable<AsyncViewRow>>() { @Override public Observable<AsyncViewRow> call(JsonObject error) { return Observable.error(new CouchbaseQueryExecutionException("Unable to execute view query due to the following view error: " + error.toString())); }}) .switchIfEmpty(asyncViewResult.rows()); } }) .flatMap(new Func1<AsyncViewRow, Observable<T>>() { @Override public Observable<T> call(AsyncViewRow row) { final String id = row.id(); return row .document(RawJsonDocument.class) .map(new Func1<RawJsonDocument, T>() { @Override public T call(RawJsonDocument rawJsonDocument) { T entity = mapToEntity(id, rawJsonDocument, entityClass); return entity; } }); }}) .filter(new Func1<T, Boolean>() { @Override public Boolean call(T t) { return t != null; } }) .onErrorResumeNext(new Func1<Throwable, Observable<T>>() { @Override public Observable<T> call(Throwable throwable) { if (throwable instanceof TranscodingException) { return Observable.error(new CouchbaseQueryExecutionException("Unable to execute view query", throwable)); } else { return Observable.error(throwable); } } }) .toList() .toBlocking() .single(); }