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

DateOnly serialization not working properly as of 2.19.0

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: Serialization
    • Labels:
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Summary

      We have a component that listens to events and saves all properties of the event to a mongo database. We set it up as generic as possible; all properties values are downcast to "object" so they all fit into the same model, which is stored into the database. We noticed that, as of version 2.19.0 which introduced an allowlist for the ObjectSerializer, that storing DateOnly values in a property of type object throws an exception, as the ObjectSerializer says the type is not allowed.

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      Version 2.19.0.

      How to Reproduce

      var client = new MongoClient("mongodb://localhost:27017");
      var database = client.GetDatabase("test");
      var collection1 = database.GetCollection<Test1>("test");
      var collection2 = database.GetCollection<Test2>("test");
      
      var instance1 = new Test1 { Value = new DateOnly(2022, 1, 1) };
      
      var instance2 = new Test2 { Value = new DateOnly(2022, 1, 1) };
      
      // Works
      await collection1.InsertOneAsync(instance1);
      
      // Crashes
      await collection2.InsertOneAsync(instance2);
      
      public class Test1
      {
          public DateOnly Value { get; set; }
      }
      
      public class Test2
      {
          public object Value { get; set; }
      }

       

       

      Additional Background

      Not applicable.

            Assignee:
            Unassigned Unassigned
            Reporter:
            ken.van.grinsven@zorgmatch.nl Ken van Grinsven
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: