-
Type: New Feature
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: 1.8.3
-
Component/s: Serialization
-
Environment:Windows 8.1
If you want (for example) to serialize all decimals as doubles (yes, I know about the loss of precision), there is no easy way to do so.
var conventions = new ConventionPack();
conventions.Add(new MemberSerializationOptionsConvention(typeof(decimal), new RepresentationSerializationOptions(BsonType.Double)));
ConventionRegistry.Register("Serialize decimal as double", conventions, t => true);
works for plain decimals in a class, but does not apply itself to arrays of decimals, or decimals in a dictionary, or arrays of decimals in a dictionary.
It would be simpler to understand if all the Serializers had a static property for the default serialization method, so you could just do
DecimalSerializer.DefaultSerializationOptions = BsonType.Double;
If that is considered too hacky, the alternative would be to make the array, dictionary, etc. deserializers honour registered conventions for their elements, instead of always using the hard coded default.