Closed
Description
This issue has been moved from a ticket on Developer Community.
[severity:I'm unable to use this version]
In .net8 using JSON source generator with property names that are preserved c# names and using JsonIgnoreCondition.WhenWritingNull, invalid sources will be generated.
public class Model
{
public string type { get; set; }
public string alias { get; set; }
}
[JsonSourceGenerationOptions(DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
[JsonSerializable(typeof(Model))]
internal partial class ModelContext : JsonSerializerContext
{
}
This will generate source with a lot of compilation errors.
It wil generate
string __value_@type = ((global::Model)value).@type;
if (__value_@type != null)
{
writer.WriteString(PropName_type, __value_@type);
}
In dotnet 7 it would generate:
if (value.@type != null)
{
writer.WriteString(PropName_type, value.@type);
}
Original Comments
Feedback Bot on 12/6/2023, 06:10 PM:
(private comment, text removed)
Original Solutions
(no solutions)