Document to WriteableMap

I am updating the question to make it clearer. From react-native, I call a java method to get a document as follows:

      public void getDocument(String documentId, Promise promise){
        Document document = database.getDocument(dbName, docId);
        if (document != null){
            // document found. resolve well

    }catch(CouchbaseLiteException e){
      // no exception caught in this block
    }catch(Exception e){
        //exception caught here

the above fails with the exception:

              java.lang.RuntimeException: Cannot convert argument of type class com.couchbase.lite.Document

again, my guess is Document type couldn’t be resolved back to react-native/Javascript as it is because doing:


works perfectly because I see the document in javascript in string format as follows exactly:


But i want to resolve something like a WritableMap. THIs one would work for e.g.:

                      WriteableMap map = new WriteableMap();
                       map.putDouble('salary', 1903.93);

so my question is simply how can I pass a found document back to react-native? Is there a simple way to convert a Document to WriteableMap (of react-native) or perhaps a json?

My friend, none of us, here, can figure out how to help you. You’ve shown no errors and we can’t even figure out, exactly, what it is you are trying to do…

If you can give us a little more detail. we can try to be of assistance.

@rut I do not have specific expertise in the Couchbase SDKs but I noticed just at a high level that WriteableMap and ReadableArray are classes from com.facebook.react.bridge:

while MutableArray returned by document.GetArray is a Couchbase class:

So perhaps the problem is the code is trying to mix apples and oranges without a conversion in between.

@blake.meike sorry i have simplified the question and hopefully it is clearer now.

At the end of the day, what you have is a collection of key value pairs. I’m not familiar with React Native at all, but perhaps there is some way to set a custom conversion method or class to handle the conversion. If not, then converting it to something else first by iterating recursively over the keys and values will do the trick.

Side note: In 3.0 Couchbase has added a toJSON method to convert various objects into a JSON string, which may help you as well.