I’m using the Cluster constructor overload that takes a string to load the configuration from the config file.
// Cluster configuration is red from the config file
cluster = new Cluster("couchbaseClients/couchbase");
Next I specify that I need to use the default serializer with a custom converter :
JsonSerializerSettings defaultDeserializationSettings = new JsonSerializerSettings
{
TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Auto,
NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
};
JsonSerializerSettings defaultSerializationSettings = new JsonSerializerSettings
{
Formatting = Newtonsoft.Json.Formatting.Indented,
TypeNameHandling = TypeNameHandling.Auto,
NullValueHandling = NullValueHandling.Ignore
};
JsonConverter myConverter = new CustomJsonConverter();
defaultDeserializationSettings.Converters.Add(myConverter);
defaultSerializationSettings.Converters.Add(myConverter);
cluster.Configuration.Serializer = () => new DefaultSerializer(defaultDeserializationSettings, defaultSerializationSettings);
Finally I open the bucket.
// Open the connection
bucket = cluster.OpenBucket();
All of this works fine except that my custom converter is not used at all.
But, with exactly the same code and a harcoded configuration, it works
var config = new ClientConfiguration
{
Serializer = () => new DefaultSerializer(defaultDeserializationSettings, defaultSerializationSettings),
Servers = new List<Uri>
{
new Uri("http://localhost:8091/pools"),
},
UseSsl = false,
BucketConfigs = new Dictionary<string, BucketConfiguration>
{
{"default", new BucketConfiguration
{
BucketName = "default",
UseSsl = false,
Password = "",
PoolConfiguration = new PoolConfiguration
{
MaxSize = 10,
MinSize = 5
}
}}
}
};
var cluster = new Cluster(config);
bucket = cluster.OpenBucket();
In this scenario, the custom converter is used.
If I’m not messing with the code, I suspect that the factory to create the serializer is already invoked after the configuration is loaded from the config file. Replacing it seems to have has no effect.
Any help appreciated.