How to update/create already serialized document (string, JObject), without IDictionary<string, object>

248 views
Skip to first unread message

ni...@machinezone.com

unread,
Mar 5, 2015, 7:31:39 PM3/5/15
to mobile-c...@googlegroups.com

(Using xamarin lite, C# but general couchbase lite question)

Couchbase document.properties is IDictionary<String, Object> properties. Objects in business logic layer have different representations of course, and include nested members, also arrays etc (not trivial 1 level key-value types). 

In order to update a document, I can serialize my objects to JObject  or just json string but I don't want to handcraft each type to convert it to dictionaries. I dont see anything in API besides IDictionary<String, Object> properties.


Is there a way to update/create document by giving it json (and not IDictionary)?

Note:
The opposite direction, ie retrieving document properties into json, is ok for me because JObject.FromObject(document.properties) is correctly handling Couchbase IDictionary<string, object> from coucbhase document and so i can correctly deserialize results into my types.

Jens Alfke

unread,
Mar 5, 2015, 7:42:18 PM3/5/15
to mobile-c...@googlegroups.com
On Mar 3, 2015, at 10:29 AM, ni...@machinezone.com wrote:

Couchbase document.properties is IDictionary<String, Object> properties. Objects in business logic layer have different representations of course, and include nested members, also arrays etc (not trivial 1 level key-value types). 

Couchbase Lite documents are JSON objects, so they can have nested arrays/dictionaries. In other words, the ‘Object’ value type can include IDictionary or IArray, as well as scalars.

—Jens

PRASANNA KUMAR

unread,
Mar 6, 2015, 2:15:54 AM3/6/15
to mobile-c...@googlegroups.com
i'll suggest you to follow the some dictionary formates

Map<String, Object> mapAuditProperties = new HashMap<String, Object>();
mapAuditProperties.put(DATES, getDateKeyValue());

/**
     * To get dateKey HashMap
     * @return  datesmap
     */
    private Object getDateKeyValue(){       
        HashMap<String, String> datesmap = new HashMap<String, String>();
        datesmap.put(CREATIONDATE, edAudits.getCreationDate());
        datesmap.put(LASTMODIFIEDDATE, edAudits.getLastModifiedDate());
        return datesmap;

Zachary Gramana

unread,
Apr 28, 2015, 2:59:56 PM4/28/15
to mobile-c...@googlegroups.com
Nika,

We’re going to be adding this use case as part of our upcoming “convenience” API.

In C#, you’ll be able to do something like:

var myObj = new Employee 
Id = "zg"
FirstName = "Zack"
LastName = "Gramana"
DepartmentId = 1
  };

db.Save(myObj);

and

var myObj = db.Get<Employee>("zg");

It wouldn’t be hard to add something like:

 db.Save("zg""{'firstName':'Zack',…}"); 

Is the use case you have in mind a HttpClient fetch-and-store from a REST endpoint?

On Mar 3, 2015, at 10:29 AM, ni...@machinezone.com wrote:

--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/8e597bc5-fbd6-4b92-bd3d-112ee8a97473%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages