We have multiple custom serializers in our codebase, many deriving from existing serializers. Now that these classes are sealed in version 3.0 of the C# drivers, we need to convert them.
Before we systematically convert them to use composition instead of inheritance, it might be useful for us to validate that there isn’t a simpler approach to each of our needs, which we either might have overlooked, or did not exist when we initially coded this.
First, a simple confirmation: We had many “Nullable” versions of serializers. We’ll switch to using NullableSerilizer.Create(baseSerializer)
. Is this the correct approach?
Second, what would be the correct way to have a value-type serializer use a specific value as the default when encountering a null value at deserialization? For example, we had a BooleanDefaultTrueSerializer
(the name says it all), and some EnumSerializer<T>
-derived serializers that mapped nulls to specific values. This is not to be confused with the default value when the field is absent. It’s really about having a default value when it’s null (legacy serialization that shouldn’t be null anymore, but which we want to continue to support).
Thanks.