This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
Support custom converters that treat non-null input as null (#40287) #40357
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Port #40287 to 3.0
cc: @eerhardt, @layomia, @ahsonkhan
Description
Adds support to allow a custom converter to return null on deserialize when the input is not null. This applies to both Nullable structs and also classes.
Without this, an
InvalidOperationException
is raised for the Nullable case and a Debug.Assert failure for the class case.There is not a valid workaround for this common so it will likely block usage of the serializer in these scenarios. The issue was requested by the community.
Regression?
No; the code is new in 3.0 (the custom converter code is < 2 months old).
Risk
Low. The code is very local to using
Nullable<T>
and an additional check is made to see if there is a converter for the nullable type before asking for a converter for the underlying type.