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

System.Decimal serialization/deserialization is contains breaking changes

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: 2.19.1
    • Component/s: None
    • Labels:
      None
    • 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

      The new System.Decimal serialization added by extension of the ObjectSerlializer generates the new JSON structure, which does not contain the type discriminator.
      After the deserialization, the data type is unexpected.

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

      2.19.1

      How to Reproduce

      public class DecimalDeserialization
      {
          [Theory]
          [InlineData("""{ "Value" : { "_t" : "System.Decimal", "_v" : NumberDecimal("1.5") } }""")] // Old format <= 2.19.0; Success
          [InlineData("""{ "Value" : NumberDecimal("1.5") }""")] // New format 2.19.1. Error: Expected type to be System.Decimal, but found MongoDB.Bson.Decimal128.
          public void ObjectSerializer_should_deserialize_decimals_successfully(string jsonValue)
          {
              var rehydrated = BsonSerializer.Deserialize<Data>(jsonValue);
              ((decimal)rehydrated.Value).Should().Be(1.5m);
              rehydrated.Value.Should().BeOfType<decimal>();
          }
       
          private sealed record Data(object Value);
      } 

      Additional Background

      The expected deserialization result of the instance of System.Decimal type should be the other instance System.Decimal type with the same value.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            yurii.zhoholiev@gmail.com Yurii Zhoholiev
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: