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

Default BsonSerializationArgs sometimes has null NominalType

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major - P3 Major - P3
    • 2.11.0
    • 2.10.0
    • Serialization
    • None

    Description

      When BsonSerializationArgs is not provided the default value will sometimes have a null value for the NominalType.

      This can result in an undesired `_t` discriminator value.

      Reproduction:

      namespace ConsoleApplication
      {
          public class C
          {
              public int X { get; set; }
          }
       
          public class Program
          {
              public static void Main()
              {
                  var c = new C { X = 1 };
       
                  using (var stringWriter = new StringWriter())
                  using (var writer = new JsonWriter(stringWriter))
                  {
                      BsonSerializer.Serialize(writer, c);
                      var json = stringWriter.ToString();
                  }
              }
          }
      }
      
      

      Results in:

      "{ \"_t\" : \"C\", \"X\" : 1 }"
      

      But the `_t` is not supposed to be there.

       

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: