I am updating the question to make it clearer. From react-native, I call a java method to get a document as follows:
@ReactMethod
public void getDocument(String documentId, Promise promise){
try{
Document document = database.getDocument(dbName, docId);
if (document != null){
// document found. resolve well
promise.resolve(document);
}else{
promise.resolve(null);
}
}catch(CouchbaseLiteException e){
// no exception caught in this block
logException(e);
promise.reject(e.getMessage());
}catch(Exception e){
//exception caught here
logExceptions(e);
promise.reject(e.getMessage());
}
}
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:
promise.resolve(documen.toString());
works perfectly because I see the document in javascript in string format as follows exactly:
Document{@0x3e8219105cee7a7-2431-47a0-a25e-605ee039a13a@1-a7ed608736c34cf5860a0d35968e6441e1f089ef(..):obj=>Dictionary{(..)a=>A,b=>B},ranks=>com.couchbase.lite.Array@1397ba,age=>20,objAr=>com.couchbase.lite.Array@5f,active=>true,type=>employee,salary=>1903.93,nl=>null}
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);
promise.resolve(map);
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?