Uploaded image for project: 'Couchbase .NET client library'
  1. Couchbase .NET client library
  2. NCBC-2217

Deserialization issues with GetAsync<T>

    XMLWordPrintable

Details

    • Bug
    • Resolution: Cannot Reproduce
    • Major
    • 3.0.0
    • 3.0.0-beta.1
    • library
    • None
    • .Net Core 3.0.1
    • 1

    Description

      I'm noticing some odd behavior when trying to do GetAsync<T> where T is a class I've specified. I would have expected that GetAsync<T> would have returned the document I've inserted, but it appears that it's returning the document within a document, with a field name of "". 

       

      Here's some sample code illustrating the issue, plus a workaround: 

       

      var connString = "couchbase://10.0.0.220";
                  var options = new ClusterOptions();            options.WithBucket("bugtest")            .WithCredentials("Administrator", "danger")            .WithServers(connString);
                  var cluster = new Cluster(connString, options);
                  var bucketResult = cluster.BucketAsync("bugtest");
                  bucketResult.Wait();
                  var collection = bucketResult.Result.DefaultCollection();
                  var testData = new TestData()            {                StringTest = "test",                IntTest = Int32.MaxValue,                DictTest = new Dictionary<string, int>(){                    {"key1", 1},                    {"key2", 2},                    {"key3", 3}                }            };
                  var key = "test:mydoc";
                  collection.InsertAsync(key, testData);
                  var getResult = collection.GetAsync(key, options =>            {            });
                  getResult.Wait();
                  var r = getResult.Result;            var badResult = r.ContentAs<TestData>(); // this should return the object we inserted, but it does not            /*
                      It looks like it's returning a document that looks like this: 
                      {"" : {<the actual document content>}}
                  */
                  //this is the workaround for Get
                  var correctResult = (JToken)(r.ContentAs<dynamic>()[""]);
                  var cr = (TestData)correctResult.ToObject(typeof(TestData)); //this returns what I would have expected.
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            daschl Michael Nitschinger
            alexcavnar Alex Cavnar
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty