Skip to content

dotnet 7 System.Text.Json JsonSerializer.Serialize exception: is marked required but does not specify a setter. #82879

@kzhui125

Description

@kzhui125

Description

using JsonSerializer.Serialize to Serialize object.

Reproduction Steps

using System.Text.Json;
using System.Text.Json.Serialization;

TestDto t = new() { Items = new() };

string jsonString = JsonSerializer.Serialize(t);
Console.WriteLine(jsonString);

public class TestDto
{
    public string? Field1 { get; set; }
    [JsonIgnore]
    public required List<string> Items { get; set; }
}

Expected behavior

no exception

Actual behavior

exception throws

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions