Skip to content

JsonIgnoreNullsAttribute Class

Marks a class or struct so that all nullable properties are omitted from the serialized JSON when their value is null, without requiring a per-property System.Text.Json.Serialization.JsonIgnoreAttribute on each one.

C#
public sealed class JsonIgnoreNullsAttribute : System.Attribute

Inheritance System.ObjectSystem.Attribute → JsonIgnoreNullsAttribute

Remarks

This attribute is a marker only. For it to take effect, the System.Text.Json.JsonSerializerOptions used during serialization must have Apply(JsonTypeInfo) registered as a System.Text.Json.Serialization.Metadata.JsonTypeInfo modifier - for example via System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.Modifiers added to System.Text.Json.JsonSerializerOptions.TypeInfoResolverChain. Abblix's AddOidcControllers registers the modifier automatically.