Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Querying _all_docs gives stack trace. #50

Closed
buckett opened this issue Jan 13, 2016 · 2 comments
Closed

Querying _all_docs gives stack trace. #50

buckett opened this issue Jan 13, 2016 · 2 comments

Comments

@buckett
Copy link
Contributor

buckett commented Jan 13, 2016

I was attempting to page through _all_docs and on the first page I'm getting a stack trace:

Exception in thread "main" com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected STRING but was BEGIN_OBJECT
    at com.google.gson.Gson.fromJson(Gson.java:822)
    at com.google.gson.Gson.fromJson(Gson.java:875)
    at com.google.gson.Gson.fromJson(Gson.java:848)
    at org.lightcouch.CouchDbUtil.JsonToObject(CouchDbUtil.java:74)
    at org.lightcouch.View.queryView(View.java:196)
    at org.lightcouch.View.queryNextPage(View.java:310)
    at org.lightcouch.View.queryPage(View.java:266)
    at uk.ac.ox.it.CouchUpdater.cleanup(CouchUpdater.java:106)
    at uk.ac.ox.it.App.importSkills(App.java:50)
    at uk.ac.ox.it.App.main(App.java:34)
Caused by: java.lang.IllegalStateException: Expected STRING but was BEGIN_OBJECT
    at com.google.gson.internal.bind.JsonTreeReader.nextString(JsonTreeReader.java:154)
    at com.google.gson.internal.bind.TypeAdapters$13.read(TypeAdapters.java:358)
    at com.google.gson.internal.bind.TypeAdapters$13.read(TypeAdapters.java:346)
    at com.google.gson.Gson.fromJson(Gson.java:810)
    ... 9 more

My code is effectively this:

        View allDocs = couchClient.view("_all_docs");
        String pageParam = null;
        Page<Document> page;
        do {
            page = allDocs.queryPage(10, pageParam, Document.class);
            // Do stuff
            pageParam = page.getNextParam();
        } while (page.isHasNext());
buckett added a commit to buckett/LightCouch that referenced this issue Jan 13, 2016
@buckett
Copy link
Contributor Author

buckett commented Jan 13, 2016

It looks like org.lightcouch.View#queryNextPage assumes that the value in a view will always be a String which isn't the case for _all_docs where you have something like:

{
id: "052cc4aa11304d58ac23b722325f84cd",
key: "052cc4aa11304d58ac23b722325f84cd",
value: {
rev: "1-241b85056f1f333f8c8e90dc79796351"
},
doc: {
_id: "052cc4aa11304d58ac23b722325f84cd",
_rev: "1-241b85056f1f333f8c8e90dc79796351",
Type: "Foo",
title: "some-val",
position: 0
}
}

@lightcouch
Copy link
Owner

Fixed in release 0.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants