-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System.Text.Json source generation should accept init-only properties with JsonIgnoreCondition.Always #66003
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json Issue DetailsDescriptionCurrently, using JSON source generation with init-only properties is not supported. However, source generation fails if there are any init-only properties present on a class at all, even those marked with Reproduction Stepspublic class Poco
{
public string Message { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
public object Info { get; init; }
} [JsonSerializable(typeof(Poco))]
public partial class MySerializerContext : JsonSerializerContext
{
} Expected behaviorSource is successfully generated and compiles, ignoring the presence of the init-only property. Actual behaviorSYSLIB1037 The type 'Poco' defines init-only properties, deserialization of which is currently not supported in source generation mode Regression?No Known WorkaroundsDo not include any init-only properties at all, even ignored. Configuration.NET 6 Other informationNo response
|
Can reproduce. Likely related to #63443. |
We won't have time to work on this for .NET 7, moving to Future. |
@eiriktsarpalis would you be interested in a community PR to address this, or is testing bandwidth also a concern? |
Hi @brantburnett, we're always open to community contributions. |
Fixed by #79828. |
Description
Currently, using JSON source generation with init-only properties is not supported. However, source generation fails if there are any init-only properties present on a class at all, even those marked with
JsonIgnoreCondition.Always
. Since such properties are not serialized or deserialized, it seems like they could be ignored for this rule as well.Reproduction Steps
Expected behavior
Source is successfully generated and compiles, ignoring the presence of the init-only property.
Actual behavior
SYSLIB1037 The type 'Poco' defines init-only properties, deserialization of which is currently not supported in source generation mode
Regression?
No
Known Workarounds
Do not include any init-only properties at all, even ignored.
Configuration
.NET 6
Other information
No response
The text was updated successfully, but these errors were encountered: