JamesNK / Newtonsoft.Json

Json.NET is a popular high-performance JSON framework for .NET
https://www.newtonsoft.com/json
MIT License
10.73k stars 3.25k forks source link

Parameter support for `JsonIgnoreAttribute` #2841

Closed danny-zegel-zocdoc closed 1 year ago

danny-zegel-zocdoc commented 1 year ago

I've starting using record types to avoid all the boiler plate code that comes along with regular classes. This generally works fine as I can use JsonPropertyAttribute with record type parameters like this

public record MyObject([JsonProperty("customName")] string SomeProperty);

however JsonIgnoreAttribute does not support properties so I can't do

public record MyObject(
    [JsonProperty("customName")] string SomeProperty,
    [JsonIgnore] string?OtherThing);

and need to fallback to using classes in those cases.

It would be great if JsonIgnoreAttribute could also support parameters like JsonPropertyAttribute does.

danny-zegel-zocdoc commented 1 year ago

sorry I realize I just need to use [property: JsonIgnore]