-
Type: Bug
-
Resolution: Duplicate
-
Priority: Unknown
-
None
-
Affects Version/s: 2.19.1
-
Component/s: None
-
None
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.
- is duplicated by
-
CSHARP-4648 Standardize handling of decimal vs Decimal128
- Closed
- is related to
-
CSHARP-4648 Standardize handling of decimal vs Decimal128
- Closed