JsonSerializerOptions.RespectRequiredConstructorParameters Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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.