I am using the .Net SDK (version 2.7.8 as of the time of this posting) to interact with a Couchbase data store. I have noticed an inconsistency with how the SDK serializes objects. If I were to have an object that I wrote as a document to couchbase (such as using _bucket.ReplaceAsync('my:object', myObject)
, then the object is serialized a certain way. Property names are converted to camel case. Enums are translated as numbers.
But then, I have the following method:
public async Task<(bool Success, string ErrorMessage)> UpdateRoleAsync(long orgId, Role role)
{
var orgKey = GetKey(orgId);
var query = new QueryRequest()
.Statement(@"UPDATE users AS org USE KEYS $orgKey
SET org.roles = ARRAY_REPLACE(org.roles, r, $role)
FOR r IN org.roles WHEN r.id = $roleId END")
.AddNamedParameter("$roleId", role.Id)
.AddNamedParameter("$role", role)
.AddNamedParameter("$orgKey", orgKey);
var result = await _usersBucket.QueryAsync<string>(query);
if (!result.Success)
{
return (false, result.ErrorMessages());
}
return (true, null);
}
When this query executes, the role
object is NOT serialized the same way. Instead of camel casing property names, they are left in the original C# casing. Instead of numbers, enums are translated as strings. This leads to this awkward result:
{
"id": 100,
"name": "Sample Organization",
"roles": [
{
"description": "The owner of a collection",
"id": 5,
"name": "Collection Owner",
"permissions": [
"collection:general:add",
"collection:general:rearrange",
"collection:general:remove",
"collection:general:userManage",
"collection:view"
],
"roleType": 0,
"scope": 4,
"type": "role"
},
{
"Type": "role",
"Id": 11963,
"Name": "New Role",
"Description": "This is my new description, get with it loser - take 2",
"Scope": "workspace",
"Permissions": [
"asset:upload",
"asset:download",
"asset:ratingColor:update",
"asset:labelSelect:update",
"asset:labelApprove:update",
"ws:update",
"ws:roleAssignment:manage",
"ws:view"
],
"RoleType": "userDefined"
}
],
"type": "organization"
}
For this example, role 11963 was the role I updated via the query, while role 5 was written via document write.
In reality, I don’t care if enums are strings or numbers, whether properties are camel cased or not. - I just want it consistent. Is there a setting I can set/override somewhere to do this, or is this a bug in the SDK?