Upraviť

Zdieľať cez


JsonSerializerOptions.RespectRequiredConstructorParameters Property

Definition

Gets or sets a value that indicates whether non-optional constructor parameters should be specified during deserialization.

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

Property Value

Exceptions

This property is set after serialization or deserialization has occurred.

Remarks

For historical reasons constructor-based deserialization treats all constructor parameters as optional by default, filling missing parameters with default values when they are not present in the JSON payload. This flag allows users to toggle that behavior as necessary for each JsonSerializerOptions instance. The default setting for this property can be toggled application-wide using the "System.Text.Json.Serialization.RespectRequiredConstructorParametersDefault" feature switch.

It is recommended that new applications always set this property to true, in combination with the closely related RespectNullableAnnotations property.

Applies to