You can set the JsonSerializerSettings.ContractResolver to a custom Pascal cased converter. Alternatively, you could annotate your POCOâs (if your using them) with [JsonProperty(âYourPascalNameâ)] to force Pascal casing.
CouchbaseClientExtensions.JsonSerializerSettings.ContractResolver = new PascalCasePropertyNamesContractResolver();
It serialized the json properties with pascalcase and stored them as i wanted in couchbase.
New thing that happens now is that i get âError converting value to type âSystem.Int64â. Path âidââŚâ
My Id is a long type fields that its name is also pascalcase as the other properties.
Can you explain this error?
By the way, when i use [JsonProperty(âidâ)] attribute above the âIdâ property, it works, but i want to understand why it happens and if there is a good way i can solve it without using JsonProperty attribute.
My recollection is that this was added because the ASP.NET 1.x client depended on id being in the document for some of itâs auto-mapping. When this changed in 2.0, the quick fix was to make the automatic object handling in .NET inject the ID.
@jmorris this is really your area, but it would be ideal from my perspective if we can find a way to not modify the doc from what weâve gotten from the app. Youâd know enough about how to do this correctly.
@Chenos@ingenthr I believe an easy work-around to this would be to the handle the JSON serialization on the application side and then use one of the non-JSON overloads: ExecuteStore(key, value) or ExecuteGet(key) on the client for storing a retrieving the document. This could be encapsulated into separate methods on the CouchbaseClientExtensions class, for example: GetJsonWithoutEmbeddedId(key). Not pretty, but would work.
After what you wrote here, i think using JsonProperty[âidâ] combined with the PascalCaseContractResolver is cleaner than the other options you suggested.
Hope that in 2.x .net client version i will have even more cleaner solution for this issue.