Επεξεργασία

Κοινή χρήση μέσω


JsonSerializerOptions.RespectNullableAnnotations Property

Definition

Gets or sets a value that indicates whether nullability annotations should be respected during serialization and deserialization.

public:
 property bool RespectNullableAnnotations { bool get(); void set(bool value); };
public bool RespectNullableAnnotations { get; set; }
member this.RespectNullableAnnotations : bool with get, set
Public Property RespectNullableAnnotations As Boolean

Property Value

Exceptions

Thrown if this property is set after serialization or deserialization has occurred.

Remarks

Nullability annotations are resolved from the properties, fields and constructor parameters

that are used by the serializer. This includes annotations stemming from attributes such as

NotNullAttribute, MaybeNullAttribute,

AllowNullAttribute and DisallowNullAttribute.

Due to restrictions in how nullable reference types are represented at run time,

this setting only governs nullability annotations of non-generic properties and fields.

It cannot be used to enforce nullability annotations of root-level types or generic parameters.

The default setting for this property can be toggled application-wide using the

"System.Text.Json.Serialization.RespectNullableAnnotationsDefault" feature switch.

Applies to