Issue with serialization

Hi

When writing to couchbase, we were sending the JObject along with the Serilization Settings so we had to repeat this code everywhere

var jObject = JObject.FromObject(cartItem, Helper.JsonSerializer);
var success = await CouchbaseHelper.CouchbaseClient.UpsertAsync(cartItem.CartItemId, jObject, expiration);

To avoid this, we came up with a better approach.

Now during the Couchbase initialization, we are setting the Serialization settings (sent from the calling application) to the Cluster
_cluster.Configuration.Serializer = (() => serializer);

and we were expecting that the ISerializer will be called while writing to Couchbase and our below code will work without any issue.
var success = await CouchbaseHelper.CouchbaseClient.UpsertAsync(cartItem.CartItemId, cartItem, expiration);

But after the above changes, byteString is not getting serialized/converted, but getting stored as byteString itself, i.e., the serializer settings/converters which we passed is not getting called. Could you please let us know if we are missing something here.

Expected
"availabilityDTO": {
“any”: {
"@type": “type.googleapis.com/AvailabilityResponse”,
“duration”: 1,
“isAvailable”: true,
“packageID”: “ccc9d241-57d4-4120-ab9b-725e656eda65”,
“packageOptionID”: “6c1dd1ac-0860-45a7-a0ee-275cf797ffa8”,
“passengerDetails”: [

Actual
"availabilityDTO": {
“any”: {
“typeUrl”: “type.googleapis.com/AvailabilityResponse”,
“value”: [
10,
36,
66,
69,
55,
69,
65,
69,
53,
65,
45,
67,

Hi @srbhaski

What SDK version are you using?

Overriding the JsonSerializerSettings on the cluster has been deprecated in favour of providing custom a Serialiser and Converter. We did this to make the serialisation process work with other serializers than just Newtonsoft.Json. This is the ticket it was done for.

A custom serializer and converter can be added during initialisation like this:

var config = new ClientConfiguration
{
    Serializer = () => new CustomSerializer(), // Couchbase.Core.Serialization.ITypeSerializer
    Converter = () => new CustomConverter(), // Couchbase.IO.Converters.IByteConverter
    Servers = new List<Uri> {new Uri("couchbase://localhost")}
    // other config
};
ClusterHelper.Initialize(config);
1 Like