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

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 0.11
    • 0.9
    • None
    • None

    Description

      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
      }

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: