[CSHARP-2155] ObjectSerializer does not properly serialize c# Decimal type Created: 26/Jan/18  Updated: 27/Oct/23  Resolved: 31/Jan/18

Status: Closed
Project: C# Driver
Component/s: BSON, Serialization
Affects Version/s: 2.4, 2.4.1, 2.4.2, 2.4.3, 2.4.4, 2.5
Fix Version/s: None

Type: Task Priority: Minor - P4
Reporter: Yarin [X] Assignee: Robert Stam
Resolution: Works as Designed Votes: 0
Labels: decimal-data-type, question, serialization
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 10



 Description   

When ObjectSerializer needs to serialize a decimal (Decimal, not Decimal128), it is treated as an object and serialized to {_t: "System.Decimal", _v: "1.5" }.



 Comments   
Comment by Robert Stam [ 31/Jan/18 ]

We can't change this, because .NET's Decimal type and BSON's Decimal128 type are not the same thing. They are both 128 bits long, but the bits are interpreted differently and the types have a different range of values.

A .NET Decimal has to be serialized with a discriminator (the "_t" part) so that during deserialization ObjectSerializer can figure out that the value is a .NET Decimal.

When ObjectSerializer encounters a BSON Decimal128 during deserialization it deserializes it into an instance of the BsonDecimal128 class (not the .NET Decimal class).

Generated at Wed Feb 07 21:41:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.