I am trying to get the meta.id
field in the json response object in the collection.get(<docId>)
call. This might sound strange because for performing a get call one should already have the id
value so why need it in the response, right? here is the thing :
in kotlin, there is the concept of data
class used for representing DTO object where all the fields should be available at construction time*. Having id
field in the response simplifies the whole deserialization process and we can simply do collection.get(<docId>).contentAs(MyDTO::class.java)
and I am good.
If we don’t have the id
field in the response, to be able to build the DTO there might be a way to do custom transcoding or custom deserialization but that seems like an overkill for such a simple need. Other option is to use N1QL query to fetch a document but going via query service for fetching a document for which the id
is available seems unnecessary and i feel that using couchbase like a key value store for these kind of use cases is the best way.
So, is there a way to include id field in the json object? are there any simpler neater alternatives to do that? should we store an id field in the user content area as well to solve this?
*There is a way to add properties after construction, but by doing that, the benefits of data class will be lost and a custom hashcode(), equals() etc. methods need to be implemented,