Currently, i am using an extension method from stackoverflow (http://stackoverflow.com/a/4944547/6939988) to serialise this as a dictionary in order to input it into a document. However, the key names are therefore not camel case and sometimes the method doesn’t know how to convert a list etc.
Another way is to serialise the object as json and then deserialise it as a dictionary then input it to the document. Then, I am assuming, the document serialises the dictionary back to json. This seams pretty inefficient.
Obviously, we can just input the dictionary key/values directly but this isn’t very nice and it means we can’t share the schema class across our teams or between couchbase server projects.
So, I am just wondering what is the best practice, and how are others dealing with this?
I’m not a Java programmer so I can’t answer the question, but my understanding is that there are a lot of Java libraries for object-to-JSON mapping; you should probably shop around and pick one that works the way you like.
I don’t think there is a single best practice; it seems to be based on people’s preferences and their priorities.
Oh, wait, that’s Swift, isn’t it? (Hint: It always helps if you clearly state what platform/language you’re concerned with. It can be hard to tell languages apart at first glance.)
Just use CBLModel. It’s already built-in, and it’s compatible with Swift.
(And if you don’t like it, then there are multiple open source Swift libraries for serializing Swift objects to/from JSON. Look around and pick your favorite.)
It’s currently best to simply manually serialize into a dictionary (I like to think of it like apple’s NSCoder). You could have a base class that passes a dictionary to a protected virtual method that will pass the dictionary in and receive all subclasses information if you like. I am currently in the R&D phase of getting a more automatic method for C#.
Looks like you have posted the same/similar question in several places. I had responded here but I will mention here again - We currently do not have support for mapping POSO to Document types and while it is on our radar, there is no immediate plans of supporting the same.
No, it isn’t. (It isn’t JSON internally, FWIW; we use a more efficient binary encoding called Fleece.)
I’m not sure how that relates to CBLModel anyway, as a query result ≠ a document.
You can implement Swift models by writing implementation of Swift’s Encoder and Decoder protocols that use CBLDictionary objects.