Skip to content

Commit c3d181e

Browse files
Merge pull request #10250 from eiriktsarpalis/stj-respectflags-improve
Remove porting tool artifacts and cross-reference the new JSO.Respect* properties.
2 parents ff47d48 + 423f632 commit c3d181e

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

xml/System.Text.Json/JsonSerializerOptions.xml

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,19 +1162,34 @@ Use <xref:System.Text.Json.Serialization.ReferenceHandler.Preserve> to enable un
11621162
<summary>Gets or sets a value that indicates whether nullability annotations should be respected during serialization and deserialization.</summary>
11631163
<value>To be added.</value>
11641164
<remarks>
1165-
<para>Nullability annotations are resolved from the properties, fields and constructor parameters</para>
1166-
<para>that are used by the serializer. This includes annotations stemming from attributes such as</para>
11671165
<para>
1168-
<see cref="T:System.Diagnostics.CodeAnalysis.NotNullAttribute" />, <see cref="T:System.Diagnostics.CodeAnalysis.MaybeNullAttribute" />,</para>
1166+
Configures the serializer to throw an exception when trying to serialize a <see langword="null" /> value from a non-nullable property getter,
1167+
or when deserializing a <see langword="null" /> value into a non-nullable property setter or constructor parameter.
1168+
Nullability annotations are resolved from the properties, fields, and constructor parameters
1169+
that are used by the serializer. This includes annotations stemming from attributes such as
1170+
<see cref="T:System.Diagnostics.CodeAnalysis.NotNullAttribute" />, <see cref="T:System.Diagnostics.CodeAnalysis.MaybeNullAttribute" />,
1171+
<see cref="T:System.Diagnostics.CodeAnalysis.AllowNullAttribute" /> and <see cref="T:System.Diagnostics.CodeAnalysis.DisallowNullAttribute" />.
1172+
</para>
11691173
<para>
1170-
<see cref="T:System.Diagnostics.CodeAnalysis.AllowNullAttribute" /> and <see cref="T:System.Diagnostics.CodeAnalysis.DisallowNullAttribute" />.</para>
1171-
<para>Due to restrictions in how nullable reference types are represented at run time,</para>
1172-
<para>this setting only governs nullability annotations of non-generic properties and fields.</para>
1173-
<para>It cannot be used to enforce nullability annotations of root-level types or generic parameters.</para>
1174-
<para>The default setting for this property can be toggled application-wide using the</para>
1175-
<para>"System.Text.Json.Serialization.RespectNullableAnnotationsDefault" feature switch.</para>
1174+
Due to restrictions in how nullable reference types are represented at run time,
1175+
this setting only governs nullability annotations of non-generic properties, fields, and constructor parameters.
1176+
It cannot be used to enforce nullability annotations of root-level types, collection elements, or generic parameters.
1177+
The default setting for this property can be toggled application-wide using the
1178+
"System.Text.Json.Serialization.RespectNullableAnnotationsDefault" feature switch.
1179+
</para>
1180+
<para>
1181+
Nullability validation functions independently of required-ness validation,
1182+
that is to say the setting has no effect in scenarios where the payload is missing a required property.
1183+
This can be configured independently using the <see langword="required" /> keyword,
1184+
the <see cref="P:System.Text.Json.Serialization.JsonRequiredAttribute" /> attribute,
1185+
or the <see cref="P:System.Text.Json.JsonSerializerOptions.RespectRequiredConstructorParameters" /> property.
1186+
</para>
1187+
<para>
1188+
It is recommended that new applications always set this property to <see langword="true" />,
1189+
in combination with the closely related <see cref="P:System.Text.Json.JsonSerializerOptions.RespectRequiredConstructorParameters" /> property.
1190+
</para>
11761191
</remarks>
1177-
<exception cref="T:System.InvalidOperationException">Thrown if this property is set after serialization or deserialization has occurred.</exception>
1192+
<exception cref="T:System.InvalidOperationException">This property is set after serialization or deserialization has occurred.</exception>
11781193
</Docs>
11791194
</Member>
11801195
<Member MemberName="RespectRequiredConstructorParameters">
@@ -1196,12 +1211,19 @@ Use <xref:System.Text.Json.Serialization.ReferenceHandler.Preserve> to enable un
11961211
<summary>Gets or sets a value that indicates whether non-optional constructor parameters should be specified during deserialization.</summary>
11971212
<value>To be added.</value>
11981213
<remarks>
1199-
<para>For historical reasons constructor-based deserialization treats all constructor parameters as optional by default.</para>
1200-
<para>This flag allows users to toggle that behavior as necessary for each <see cref="T:System.Text.Json.JsonSerializerOptions" /> instance.</para>
1201-
<para>The default setting for this property can be toggled application-wide using the</para>
1202-
<para>"System.Text.Json.Serialization.RespectRequiredConstructorParametersDefault" feature switch.</para>
1214+
<para>
1215+
For historical reasons constructor-based deserialization treats all constructor parameters as optional by default,
1216+
filling missing parameters with default values when they are not present in the JSON payload.
1217+
This flag allows users to toggle that behavior as necessary for each <see cref="T:System.Text.Json.JsonSerializerOptions" /> instance.
1218+
The default setting for this property can be toggled application-wide using the
1219+
"System.Text.Json.Serialization.RespectRequiredConstructorParametersDefault" feature switch.
1220+
</para>
1221+
<para>
1222+
It is recommended that new applications always set this property to <see langword="true" />,
1223+
in combination with the closely related <see cref="P:System.Text.Json.JsonSerializerOptions.RespectNullableAnnotations" /> property.
1224+
</para>
12031225
</remarks>
1204-
<exception cref="T:System.InvalidOperationException">Thrown if this property is set after serialization or deserialization has occurred.</exception>
1226+
<exception cref="T:System.InvalidOperationException">This property is set after serialization or deserialization has occurred.</exception>
12051227
</Docs>
12061228
</Member>
12071229
<Member MemberName="TryGetTypeInfo">

0 commit comments

Comments
 (0)