Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-147

Cannot deserialize JSON with a nested class where the first property is a Guid

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 0.11
    • Affects Version/s: 0.9
    • Component/s: None
    • Labels:
      None

      This occurs on today's git build (8d1d29365ebefea40d2c).

      The problem only happens if the Guid is the first property of the nested type. If you swap the order of the guid and int for the Child class, it will work.

      public class Parent
      {
      public Child Child

      { get; set; }
      }

      public class Child
      {
      public Guid Id { get; set; }

      public int A

      { get; set; }

      }

      [Test]
      public void Test()
      {
      var p = new Parent

      { Child = new Child() }

      ;
      p.Child.A = 1;
      var json = p.ToJson();
      BsonSerializer.Deserialize<Parent>(json); // throws Unexpected element exception
      }

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            bling Bailey Ling
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: