PROPERTY

JsonSerializerOptions.RespectNullableAnnotations

Opts into enforcement of supported nullable annotations on members and constructor parameters. It does not make an omitted property required, nor enforce every generic or collection-element annotation. Use required-member and domain validation separately.

Formal Syntax & Structure

csharp syntaxcsharp
new JsonSerializerOptions { RespectNullableAnnotations = true }

Working Example

Example Snippetcsharp
using System;using System.IO;using System.Collections.Generic;using System.Text.Json;var options = new JsonSerializerOptions { RespectNullableAnnotations = true }; Console.WriteLine(options.RespectNullableAnnotations); // True
C# & .NET Reference