[CSHARP-376] Use IBsonSerializationOptions in Deserialize/Serialize methods in the various Bson/Serialization/Serializers/* Created: 04/Jan/12 Updated: 20/Mar/14 Resolved: 04/Jan/12 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | 1.3.1 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Blocker - P1 |
| Reporter: | Doug Marien | Assignee: | Robert Stam |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | driver, serialization | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||
| Description |
|
Possibly related to I noticed in the various serializers in Bson/Serialization/Serializers/ that the Deserialize and Serialize methods were ignoring the given IBsonSerializationOptions. Is this by design? I recently came across an issue by attempting to use the BsonRepresentationAttribute on a collection, e.g.: [BsonRepresentation(BsonType.Int64, AllowOverflow = true)] Then I hit an OverflowException when calling ToJson on my object: System.OverflowException: Arithmetic operation resulted in an overflow. |
| Comments |
| Comment by Robert Stam [ 04/Jan/12 ] |
|
It's not a C# restriction... I probably didn't say it very well! The custom attribute is being applied to the property named Ids. The C# driver assumes that this attribute is defining serialization options for the serializer for List<UInt64> (in other words, the serializer for the Ids property as a whole), not for the serializer for UInt64. What is needed is some way to provide options that are applied to the elements of the collection rather than to the collection itself. By the way, you don't get compile time errors because as far as C# is concerned any attribute can be applied to any property (subject to the AttributeUsage defined for it). And you don't get a runtime error because the serializer for List<UInt64> ignores any options provided because it doesn't use any. |
| Comment by Doug Marien [ 04/Jan/12 ] |
|
I didn't realize C# had a restriction as to the usage of custom attributes? Were you planning on using BsonRepresentationAttribute to apply to a List<> or other collection? In that case does AllowOverflow or AllowTruncation make sense? Or are you planning on creating a new attribute that is more explicit about being applied to the collection types? |
| Comment by Robert Stam [ 04/Jan/12 ] |
|
The way you have it written the attribute is being applied to the List, not to the elements of the list (which there isn't a way to do yet). This is related to I'm going to close this one and leave |