Fix default value population for renamed constructor parameters - #3120
Open
HengYpinn wants to merge 1 commit into
Open
Fix default value population for renamed constructor parameters#3120HengYpinn wants to merge 1 commit into
HengYpinn wants to merge 1 commit into
Conversation
HengYpinn
force-pushed
the
fix-3119-renamed-constructor-default
branch
from
August 12, 2026 08:47
a4f9bd3 to
0ea1b0e
Compare
HengYpinn
marked this pull request as ready for review
August 12, 2026 08:49
HengYpinn
force-pushed
the
fix-3119-renamed-constructor-default
branch
from
August 12, 2026 09:02
0ea1b0e to
04a304a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #3119.
Related context: #1199.
Summary
Root cause
Constructor parameters were initially matched to members before the parameter's
JsonPropertyAttribute.PropertyNamewas resolved. Later, missing-value processing compared a resolved constructor JSON name with an underlying CLR member name. Consequently, explicitly assigning the same renamed JSON name to a member and constructor parameter did not reliably link them or inherit the member's default settings.Compatibility
This preserves the behavior documented in #1199: a constructor parameter named
textis not linked to a member serialized asmyTextunless the parameter explicitly uses[JsonProperty("myText")](or is itself namedmyText). The fix does not add a broad CLR-name fallback.User impact
Immutable models using explicit
JsonPropertyrenames withDefaultValueHandling.Populatenow receive their configured constructor default during deserialization instead ofnull.Validation
dotnet test Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj -f net8.0(3,519 passed)dotnet test Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj -f net6.0(3,515 passed)dotnet build Src/Newtonsoft.Json/Newtonsoft.Json.csproj -c Release(all library target frameworks built successfully)