Skip to content

JsonIgnoreNullsModifier Class

Provides a System.Text.Json.Serialization.Metadata.JsonTypeInfo modifier that enforces null-omission for all nullable properties of types decorated with JsonIgnoreNullsAttribute.

C#
public static class JsonIgnoreNullsModifier

Inheritance System.Object → JsonIgnoreNullsModifier

Remarks

Register Apply(JsonTypeInfo) via System.Text.Json.JsonSerializerOptions.TypeInfoResolverChain to activate the attribute:

C#
options.TypeInfoResolverChain.Add(
    new DefaultJsonTypeInfoResolver { Modifiers = { JsonIgnoreNullsModifier.Apply } });

Methods

JsonIgnoreNullsModifier.Apply(JsonTypeInfo) Method

A System.Text.Json.Serialization.Metadata.JsonTypeInfo modifier that sets ShouldSerialize to skip null values on every nullable property of any type decorated with JsonIgnoreNullsAttribute.

C#
public static void Apply(System.Text.Json.Serialization.Metadata.JsonTypeInfo typeInfo);

Parameters

typeInfo System.Text.Json.Serialization.Metadata.JsonTypeInfo