Bucket.Insert method ignores first letter capitalisation of document properties

Hi everyone

I have been inserting documents using IBucket’s IOperationResult Insert(string key, T value) passing in a Dictionary<string, string> as the value and the method seems to ignore any first letter capitals when creating the documents. Is this a known issue or behaviour? Is there a way to work around it?

@nonorval

The default JSON serializer specifically uses camel case attribute names. You can override this by providing a custom ITypeSerializer in your ClientConfiguration. The simplest option is to make a DefaultTypeSerializer and pass your own Newtonsoft.Json configuration that doesn’t include the CamelCasePropertyNamesContractResolver.

2 Likes

Thanks so much for the super quick reply @btburnett3! I have added a default Newtonsoft serializer like you explained and it seems to work perfectly. My cluster config (very basic) is below. Is this what you had in mind? I couldn’t find the DefaultTypeSerializer class, but used DefaultSerializer. Is this correct?

var config = new ClientConfiguration
{
    Servers = new List<Uri> { new Uri(server.scheme + server.address) }
};

config.Serializer = () =>
{
    Newtonsoft.Json.JsonSerializerSettings serializerSettings = new Newtonsoft.Json.JsonSerializerSettings();

    return new DefaultSerializer(serializerSettings, serializerSettings);
};

var cluster = new Cluster(config);

@nonorval

Yes, that’s it!

3 Likes

Great, thanks @btburnett3! :slight_smile:

2 Likes