How to save the whole object to couchbase document such as converting it to JSON or reading it back. I am using couchbase.lite(2.5.0)

Using mutableDocument and trying to save a complete Class Object . How to achieve the same. TIA.

I am creating the DB from couchbase session as mentioned in Travel Sample and I can not see the PutProperties method for document.

You can create a MutableDocument with JSON data and calling to save the document. Basically something like this:

MutableDocument doc = new MutableDocument(json);
MutableDocument doc = new MutableDocument(“CUSTOM_DOCUMENT_ID”, json);

Thanks @pasin for the tip. Can you please specify what json is in your sample code?

From (Java) api reference I find these constructors:

//Creates a new Document object with a new random UUID.
MutableDocument(Map<String,Object> data)
//Initializes a new CBLDocument object with a new random UUID and the dictionary as the content.
MutableDocument(String id)
//Creates a new Document object with the given ID.
MutableDocument(String id, Map<String,Object> data)
//Initializes a new Document object with a given ID and the dictionary as the content.

and can’t mange to create the MutableDocument form Json string.


Did you try converting the JSON string to Map<String, Object>?

Converting to map should work out of the box… but why converting POJO to Json and then to Map? It should be easier, in my opinion, to directly convert your obj to Map with a few lines of code or an object mapper library.

how to read it back?