Dictionary key (in a class) always is lowercase after serialization to json


#1

Anyone know how to solve this?
I’m using 2.0 client with Newtonsoft Json 6.0
When I store class object to couchbase which contain dictionary, the value of the key is always stored as lowercase.
“contracts”: {
“internal”: {
“eurusd”: {
“bid”: 0,
“ask”: 0,
“volume”: 0,
}
}
}
But the result is correct when I use JsonConvert.SerializeObject.
“Contracts”: {
“Internal”: {
“EURUSD”: {
“bid”: 0,
“ask”: 0,
“volume”: 0,
}
}
}


#2

The Default JSON serialiser settings uses the CamelCasePropertyNamesContractResolver. On your couchbase client, you can pass in an instance of ClientConfiguration, of which you can set the serialiser and deserialiser settings to the DefaultContract resolver, which should solve your problem.


#3

I’ve tried set it to default resolver, but it doesn’t work.
Am I doing this in wrong way?

CbCluster.Configuration.SerializationSettings.ContractResolver = new DefaultContractResolver();
CbCluster.Configuration.DeserializationSettings.ContractResolver = new DefaultContractResolver();


#4

I imagine you are using the Upsert method to store your data?

You are not doing it wrong, there is a bug open for this problem, as at the moment upsert methods on the bucket are not using the buckets configured transcoder because it does not use the correct constructor that takes it.

http://www.couchbase.com/issues/browse/NCBC-733

Unfortunately, I am having the same problem, and can only way until it’s fixed and pushed out in the next release (hopefully)