Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Support custom converters that treat non-null input as null#40287

Merged
steveharter merged 1 commit intodotnet:masterfrom
steveharter:CustomConverter
Aug 15, 2019
Merged

Support custom converters that treat non-null input as null#40287
steveharter merged 1 commit intodotnet:masterfrom
steveharter:CustomConverter

Conversation

@steveharter
Copy link
Contributor

Adds support to allow a custom converter to return null on deserialize when the input is not null. This applies to both Nullable<T> and classes.

Without this, an InvalidOperationException is raised for the Nullable<T> case and a Debug.Assert failure for the class case.

Fixes https://github.com/dotnet/corefx/issues/40229

I will recommend porting this to 3.0 once in master as the scenario is valid, the fix is low-risk, and common enough to be a blocking issue for many.

@steveharter steveharter added this to the 5.0 milestone Aug 13, 2019
@steveharter steveharter self-assigned this Aug 13, 2019
}

// Assume a single property.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: assert token type is StartObject to be consistent with below assertions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The asserts in this converter are unnecessary since the semantics are verified by the calling test. I added the other assert and comment for readability.

@steveharter steveharter merged commit ba54c40 into dotnet:master Aug 15, 2019
@steveharter steveharter deleted the CustomConverter branch August 15, 2019 16:04
steveharter added a commit to steveharter/dotnet_corefx that referenced this pull request Aug 15, 2019
@ahsonkhan
Copy link

case and a Debug.Assert failure for the class case.

What happens in release?

// Null values were already handled.
Debug.Assert(value != null);

Set(state.Current.ReturnValue, (TDeclaredProperty)value);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If value could be null here now, could this cast (and subsequent call to Set), null ref somewhere down the call stack?

Copy link

@ahsonkhan ahsonkhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully understand the underlying issue (and Nullable support) that this is fixing, but the change makes sense.

Anipik pushed a commit that referenced this pull request Aug 15, 2019
* [release/3.0]Handle `UnparseableExtension` status code when building X509Chain on … (#40117)

Ignore `UnparseableExtension` status code when building X509Chain on OSX

* [release/3.0] Update dependencies from 3 repositories (#40308)

* Update dependencies from https://github.com/dotnet/core-setup build 20190814.02

- Microsoft.NETCore.App - 3.0.0-preview9-19414-02
- Microsoft.NETCore.DotNetHostPolicy - 3.0.0-preview9-19414-02
- Microsoft.NETCore.DotNetHost - 3.0.0-preview9-19414-02

* Update dependencies from https://github.com/dotnet/arcade build 20190812.7

- Microsoft.DotNet.XUnitExtensions - 2.4.1-beta.19412.7
- Microsoft.DotNet.XUnitConsoleRunner - 2.5.1-beta.19412.7
- Microsoft.DotNet.VersionTools.Tasks - 1.0.0-beta.19412.7
- Microsoft.DotNet.ApiCompat - 1.0.0-beta.19412.7
- Microsoft.DotNet.Arcade.Sdk - 1.0.0-beta.19412.7
- Microsoft.DotNet.Build.Tasks.Configuration - 1.0.0-beta.19412.7
- Microsoft.DotNet.Build.Tasks.Feed - 2.2.0-beta.19412.7
- Microsoft.DotNet.Build.Tasks.Packaging - 1.0.0-beta.19412.7
- Microsoft.DotNet.CodeAnalysis - 1.0.0-beta.19412.7
- Microsoft.DotNet.CoreFxTesting - 1.0.0-beta.19412.7
- Microsoft.DotNet.GenAPI - 1.0.0-beta.19412.7
- Microsoft.DotNet.GenFacades - 1.0.0-beta.19412.7
- Microsoft.DotNet.Helix.Sdk - 2.0.0-beta.19412.7
- Microsoft.DotNet.RemoteExecutor - 1.0.0-beta.19412.7

* Update dependencies from https://github.com/dotnet/standard build 20190814.3

- NETStandard.Library - 2.1.0-prerelease.19414.3

* fixing ZipPackagePart.GetStreamCore crashes with NotSupportedException (#40355)

ZipArchiveEntry only ever supports opening once when the backing archive is in Create mode,  and the backing stream is non-seekable, so we shouldn't call SetLength in that case. You could still open an archive in Update mode then call part.GetStream(FileMode.Create), in which case we'll want this call to SetLength, so we only avoid this call when the backing Archive is in Create mode.

updating test to explicitly test the Update path for ZipPackage

skip UAP since we don't have access to the file system to create the .zip

undo accidental change to existing test

removing unnecessary variable

* Support custom converters that treat non-null input as null (#40287) (#40357)
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nullable struct converter

3 participants