Reputation: 25
The 3rd assert fails. Is it a CouchbaseClient bug?
private class StoreJsonTest
{
public int Id { get; set; }
public string StrProp { get; set; }
public int IntProp { get; set; }
}
[Test]
public void CouchBase()
{
var storeJsonTest = new StoreJsonTest() {Id = 1, StrProp = "Test str prop", IntProp = 10};
string key ="testStoreJson"+ Guid.NewGuid().ToString();
CouchbaseClient couchbaseClient = new CouchbaseClient();
couchbaseClient.StoreJson(StoreMode.Add, key, storeJsonTest);
var extractedJson = couchbaseClient.GetJson<StoreJsonTest>(key);
Assert.That(extractedJson.StrProp == storeJsonTest.StrProp);
Assert.That(extractedJson.IntProp == storeJsonTest.IntProp);
Assert.That(extractedJson.Id == storeJsonTest.Id);
}
How do I store the Id property to couchbase?
Upvotes: 1
Views: 80
Reputation: 36
Add the following line somewhere in your application startup:
CouchbaseClientExtensions.JsonSerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
The default contract resolver is an internal implementation that serializes everything except ID properties.
'CamelCasePropertyNamesContractResolver'
comes from the Newtonsoft.Json.Serialization
namespace.
Upvotes: 2