Array Document Get

I am using Couchbase server version 3.0.1, and client version java-client.2.0.1
My document structure is


key = k1
value = [ “199601000:999999999” ]


key = k2
value = [ “00003226”, “00002018”, “01437087”, “00006024” ]


key = k3
value = [ “199601000:999999999”, “234601000:923499990” ]


I cannot change the format of data as the data is not created by me, rather coming from other systems, which i dont have control.

Now, using the new java-client.2.0.1, i am not able to retrive the document.
Please let me know the java code steps to read the document without exception.
Thanks in advance.

Error Stack Trace:
com.couchbase.client.java.error.TranscodingException: Could not decode document with ID k1
at com.couchbase.client.java.transcoder.AbstractTranscoder.decode(AbstractTranscoder.java:55)
at com.couchbase.client.java.CouchbaseAsyncBucket$1.call(CouchbaseAsyncBucket.java:136)
at com.couchbase.client.java.CouchbaseAsyncBucket$1.call(CouchbaseAsyncBucket.java:132)
at rx.internal.operators.OperatorMap$1.onNext(OperatorMap.java:54)
at rx.internal.operators.OperatorFilter$1.onNext(OperatorFilter.java:54)
at rx.internal.operators.OperatorSubscribeOn$1$1$1.onNext(OperatorSubscribeOn.java:76)
at rx.subjects.SubjectSubscriptionManager$SubjectObserver.onNext(SubjectSubscriptionManager.java:224)
at rx.subjects.AsyncSubject.onCompleted(AsyncSubject.java:101)
at com.couchbase.client.core.ResponseHandler.onEvent(ResponseHandler.java:95)
at com.couchbase.client.core.ResponseHandler.onEvent(ResponseHandler.java:43)
at com.couchbase.client.deps.com.lmax.disruptor.BatchEventProcessor.run(BatchEventProcessor.java:128)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at com.couchbase.client.deps.io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
at java.lang.Thread.run(Thread.java:781)
Caused by: java.lang.IllegalStateException: Expecting Object as root level object, was: START_ARRAY
at com.couchbase.client.java.transcoder.JacksonTransformers$JsonObjectDeserializer.deserialize(JacksonTransformers.java:144)
at com.couchbase.client.java.transcoder.JacksonTransformers$JsonObjectDeserializer.deserialize(JacksonTransformers.java:137)
at com.couchbase.client.deps.com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3051)
at com.couchbase.client.deps.com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2146)
at com.couchbase.client.java.transcoder.JsonTranscoder.stringToJsonObject(JsonTranscoder.java:78)
at com.couchbase.client.java.transcoder.JsonTranscoder.doDecode(JsonTranscoder.java:64)
at com.couchbase.client.java.transcoder.JsonTranscoder.doDecode(JsonTranscoder.java:40)
at com.couchbase.client.java.transcoder.AbstractTranscoder.decode(AbstractTranscoder.java:42)
… 14 more

How did you add the documents to the bucket? That will influence the answer.

Hi, this is easy to fix. Since your data is a json array instead of an object you need to use the JsonArrayDocument instead. So try:

bucket.get("id", JsonArrayDocument.class);

Note that relating to @ingenthr’s comment, here it seems that the flags are decodable already, but please also tell us how you store it so we can tell you it is best practice.

Thank you, Able to work with JsonArrayDocument.class Type parameter.

Great to hear it works for you! Let us know if you need anything else.

Hi,
I am getting same type of error, so how should i give it
bucket.get("id", JsonArrayDocument.class); in scala