You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update Utf8JsonWriter for null strings, double/single formatting, and consistency. (#3143)
* Update Utf8JsonWriter for null strings, double/single formatting, and
consistency.
* Fix the IBufferWriter<byte> format since using back-ticks didn't work.
* Address PR feedback.
Copy file name to clipboardExpand all lines: xml/System.Text.Json/Utf8JsonWriter.xml
+40-28Lines changed: 40 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -30,9 +30,9 @@
30
30
31
31
`Utf8JsonWriter` writes the text sequentially with no caching and by default adheres to the [JSON RFC](https://tools.ietf.org/html/rfc8259), with the exception of writing comments.
32
32
33
-
A method that attempts to write invalid JSON when validation is enabled throws a <xref:System.InvalidOperationException> with a context-specific error message.
33
+
A method that attempts to write invalid JSON when validation is enabled throws an <xref:System.InvalidOperationException> with a context-specific error message.
34
34
35
-
To be able to format the output with indentation and white space OR to skip validation, create an instance of <xref:System.Text.Json.JsonWriterOptions> and pass it in to the writer.
35
+
To be able to format the output with indentation and white space, to skip validation, OR to customize the escaping behavior, create an instance of <xref:System.Text.Json.JsonWriterOptions> and pass it in to the writer.
36
36
37
37
]]></format>
38
38
</remarks>
@@ -55,8 +55,8 @@ To be able to format the output with indentation and white space OR to skip vali
55
55
</Parameters>
56
56
<Docs>
57
57
<paramname="bufferWriter">The destination for writing JSON text.</param>
58
-
<paramname="options">Defines the customized behavior of the <seecref="T:System.Text.Json.Utf8JsonWriter" /> By default, it writes minimized JSON (with no extra whitespace) and validates that the JSON being written is structurally valid according to the JSON RFC.</param>
59
-
<summary>Constructs a new <seecref="T:System.Text.Json.Utf8JsonWriter" /> instance with a specified <seelangword="System.Buffers.IBufferWriter<System.Byte>" />.</summary>
58
+
<paramname="options">Defines the customized behavior of the <seecref="T:System.Text.Json.Utf8JsonWriter" />. By default, it writes minimized JSON (with no extra white space) and validates that the JSON being written is structurally valid according to the JSON RFC.</param>
59
+
<summary>Initializes a new instance of the <seecref="T:System.Text.Json.Utf8JsonWriter" /> class using the specified <seecref="T:System.Buffers.IBufferWriter`1" /> to write the output to and customization options.</summary>
60
60
<remarks>To be added.</remarks>
61
61
<exceptioncref="T:System.ArgumentNullException">
62
62
<paramrefname="bufferWriter" /> is <seelangword="null" />.</exception>
@@ -79,8 +79,8 @@ To be able to format the output with indentation and white space OR to skip vali
79
79
</Parameters>
80
80
<Docs>
81
81
<paramname="utf8Json">The destination for writing JSON text.</param>
82
-
<paramname="options">Defines the customized behavior of the <seecref="T:System.Text.Json.Utf8JsonWriter" /> By default, it writes minimized JSON (with no extra whitespace) and validates that the JSON being written is structurally valid according to the JSON RFC.</param>
83
-
<summary>Constructs a new <seecref="T:System.Text.Json.Utf8JsonWriter" /> instance with a specified <paramrefname="utf8Json" />.</summary>
82
+
<paramname="options">Defines the customized behavior of the <seecref="T:System.Text.Json.Utf8JsonWriter" />. By default, it writes minimized JSON (with no extra white space) and validates that the JSON being written is structurally valid according to the JSON RFC.</param>
83
+
<summary>Initializes a new instance of the <seecref="T:System.Text.Json.Utf8JsonWriter" /> class using the specified stream to write the output to and customization options.</summary>
84
84
<remarks>To be added.</remarks>
85
85
<exceptioncref="T:System.ArgumentNullException">
86
86
<paramrefname="utf8Json" /> is <seelangword="null" />.</exception>
@@ -322,8 +322,8 @@ In the case of <xref:System.IO.Stream>, this writes the data to the stream and f
<summary>Gets the custom behavior when writing JSON using this instance, which indicates whether to format the output while writing and whether to skip structural JSON validation.</summary>
326
-
<value>An object that defines the behavior of this instance for formattingand validation.</value>
325
+
<summary>Gets the custom behavior when writing JSON using this instance, which indicates whether to format the output while writing, whether to skip structural JSON validation, and which characters to escape.</summary>
326
+
<value>The custom behavior of this instance of the writer for formatting, validating, and escaping.</value>
327
327
<remarks>To be added.</remarks>
328
328
</Docs>
329
329
</Member>
@@ -383,7 +383,7 @@ The <xref:System.Text.Json.Utf8JsonWriter> will continue to use the original wri
383
383
384
384
## Remarks
385
385
386
-
The <xref:System.Text.Json.Utf8JsonWriter> will continue to use the original writer options but now writes to `bufferWriter` as the new destination.
386
+
The <xref:System.Text.Json.Utf8JsonWriter> will continue to use the original writer options but now write to `bufferWriter` as the new destination.
387
387
388
388
]]></format>
389
389
</remarks>
@@ -806,7 +806,7 @@ The property name should already be escaped when the instance of <xref:System.Te
<paramname="value">The UTF-16 encoded value to be written as a UTF-8 transcoded JSON comment within /*..*/.</param>
846
+
<paramname="value">The UTF-16 encoded value to be written as a UTF-8 transcoded JSON comment within `/*..*/`.</param>
847
847
<summary>Writes a UTF-16 text value as a JSON comment.</summary>
848
848
<remarks>
849
849
<format><![CDATA[
@@ -854,11 +854,11 @@ The comment value is not escaped before writing.
854
854
855
855
]]></format>
856
856
</remarks>
857
-
<exceptioncref="T:System.ArgumentException">The specified value is too large OR.
857
+
<exceptioncref="T:System.ArgumentException">The specified value is too large.
858
858
859
859
-or-
860
860
861
-
<paramrefname="value" /> contains a comment delimiter (that is, */).</exception>
861
+
<paramrefname="value" /> contains a comment delimiter (that is, `*/`).</exception>
862
862
</Docs>
863
863
</Member>
864
864
<MemberMemberName="WriteCommentValue">
@@ -880,7 +880,7 @@ The comment value is not escaped before writing.
880
880
<ParameterName="value"Type="System.String" />
881
881
</Parameters>
882
882
<Docs>
883
-
<paramname="value">The UTF-16 encoded value to be written as a UTF-8 transcoded JSON comment within /*..*/.</param>
883
+
<paramname="value">The UTF-16 encoded value to be written as a UTF-8 transcoded JSON comment within `/*..*/`.</param>
884
884
<summary>Writes a string text value as a JSON comment.</summary>
885
885
<remarks>
886
886
<format><![CDATA[
@@ -895,7 +895,7 @@ The comment value is not escaped before writing.
895
895
896
896
-or-
897
897
898
-
<paramrefname="value" /> contains a comment delimiter (that is, */).</exception>
898
+
<paramrefname="value" /> contains a comment delimiter (that is, `*/`).</exception>
899
899
<exceptioncref="T:System.ArgumentNullException">The <paramrefname="value" /> parameter is <seelangword="null" />.</exception>
900
900
</Docs>
901
901
</Member>
@@ -1167,7 +1167,7 @@ The property name is escaped before writing.
1167
1167
1168
1168
## Remarks
1169
1169
1170
-
Writes the <xref:System.Double> using the default <xref:System.Buffers.StandardFormat> (that is, 'G').
1170
+
Writes the <xref:System.Double> using the default <xref:System.Buffers.StandardFormat> (that is, 'G') on .NET Core 3.0 or later versions. Uses 'G17' on any other framework.
1171
1171
1172
1172
The property name is escaped before writing.
1173
1173
@@ -1281,7 +1281,7 @@ The property name is escaped before writing.
1281
1281
1282
1282
## Remarks
1283
1283
1284
-
Writes the <xref:System.Single> using the default <xref:System.Buffers.StandardFormat> (that is, 'G').
1284
+
Writes the <xref:System.Single> using the default <xref:System.Buffers.StandardFormat> (that is, 'G') on .NET Core 3.0 or later versions. Uses 'G9' on any other framework.
1285
1285
1286
1286
The property name is escaped before writing.
1287
1287
@@ -1443,7 +1443,7 @@ The property name is escaped before writing.
1443
1443
1444
1444
## Remarks
1445
1445
1446
-
Writes the <xref:System.Double> using the default <xref:System.Buffers.StandardFormat> (that is, 'G').
1446
+
Writes the <xref:System.Double> using the default <xref:System.Buffers.StandardFormat> (that is, 'G') on .NET Core 3.0 or later versions. Uses 'G17' on any other framework.
1447
1447
1448
1448
The property name is escaped before writing.
1449
1449
@@ -1557,7 +1557,7 @@ The property name is escaped before writing.
1557
1557
1558
1558
## Remarks
1559
1559
1560
-
Writes the <xref:System.Single> using the default <xref:System.Buffers.StandardFormat> (that is, 'G').
1560
+
Writes the <xref:System.Single> using the default <xref:System.Buffers.StandardFormat> (that is, 'G') on .NET Core 3.0 or later versions. Uses 'G9' on any other framework.
1561
1561
1562
1562
The property name is escaped before writing.
1563
1563
@@ -1720,7 +1720,7 @@ The property name is escaped before writing.
1720
1720
1721
1721
## Remarks
1722
1722
1723
-
Writes the <xref:System.Double> using the default <xref:System.Buffers.StandardFormat> (that is, 'G').
1723
+
Writes the <xref:System.Double> using the default <xref:System.Buffers.StandardFormat> (that is, 'G') on .NET Core 3.0 or later versions. Uses 'G17' on any other framework.
1724
1724
1725
1725
The property name is escaped before writing.
1726
1726
@@ -1837,7 +1837,7 @@ The property name is escaped before writing.
1837
1837
1838
1838
## Remarks
1839
1839
1840
-
Writes the <xref:System.Single> using the default <xref:System.Buffers.StandardFormat> (that is, 'G').
1840
+
Writes the <xref:System.Single> using the default <xref:System.Buffers.StandardFormat> (that is, 'G') on .NET Core 3.0 or later versions. Uses 'G9' on any other framework.
1841
1841
1842
1842
The property name is escaped before writing.
1843
1843
@@ -2001,7 +2001,7 @@ The property name should already be escaped when the instance of <xref:System.Te
2001
2001
2002
2002
## Remarks
2003
2003
2004
-
Writes the <xref:System.Double> using the default <xref:System.Buffers.StandardFormat> (that is, 'G').
2004
+
Writes the <xref:System.Double> using the default <xref:System.Buffers.StandardFormat> (that is, 'G') on .NET Core 3.0 or later versions. Uses 'G17' on any other framework.
2005
2005
2006
2006
The property name should already be escaped when the instance of <xref:System.Text.Json.JsonEncodedText> was created.
2007
2007
@@ -2112,7 +2112,7 @@ The property name should already be escaped when the instance of <xref:System.Te
2112
2112
2113
2113
## Remarks
2114
2114
2115
-
Writes the <xref:System.Single> using the default <xref:System.Buffers.StandardFormat> (that is, 'G').
2115
+
Writes the <xref:System.Single> using the default <xref:System.Buffers.StandardFormat> (that is, 'G') on .NET Core 3.0 or later versions. Uses 'G9' on any other framework.
2116
2116
2117
2117
The property name should already be escaped when the instance of <xref:System.Text.Json.JsonEncodedText> was created.
2118
2118
@@ -2264,7 +2264,7 @@ This method writes the <xref:System.Decimal> value using the default <xref:Syste
2264
2264
2265
2265
## Remarks
2266
2266
2267
-
This method writes the <xref:System.Double> value using the default <xref:System.Buffers.StandardFormat> (that is, 'G').
2267
+
This method writes the <xref:System.Double> value using the default <xref:System.Buffers.StandardFormat> (that is, 'G') on .NET Core 3.0 or later versions. Uses 'G17' on any other framework.
2268
2268
2269
2269
]]></format>
2270
2270
</remarks>
@@ -2363,7 +2363,7 @@ This method writes the <xref:System.Int64> value using the default <xref:System.
2363
2363
2364
2364
## Remarks
2365
2365
2366
-
This method writes the <xref:System.Single> value using the default <xref:System.Buffers.StandardFormat> (that is, 'G').
2366
+
This method writes the <xref:System.Single> value using the default <xref:System.Buffers.StandardFormat> (that is, 'G') on .NET Core 3.0 or later versions. Uses 'G9' on any other framework.
2367
2367
2368
2368
]]></format>
2369
2369
</remarks>
@@ -2756,7 +2756,7 @@ The property name should already be escaped when the instance of <xref:System.Te
2756
2756
</remarks>
2757
2757
<exceptioncref="T:System.InvalidOperationException">The depth of the JSON has exceeded the maximum depth of 1000.
2758
2758
2759
-
- or -
2759
+
-or-
2760
2760
2761
2761
Validation is enabled, and this method would result in writing invalid JSON.</exception>
2762
2762
</Docs>
@@ -2934,7 +2934,7 @@ The property name should already be escaped when the instance of <xref:System.Te
2934
2934
</remarks>
2935
2935
<exceptioncref="T:System.InvalidOperationException">The depth of the JSON has exceeded the maximum depth of 1000.
2936
2936
2937
-
- or -
2937
+
-or-
2938
2938
2939
2939
Validation is enabled, and this method would result in writing invalid JSON.</exception>
2940
2940
</Docs>
@@ -3155,6 +3155,8 @@ The property name and value are escaped before writing.
3155
3155
3156
3156
The property name and value are escaped before writing.
3157
3157
3158
+
If `value` is `null`, the JSON **null** value is written, as if the <xref:System.Text.Json.Utf8JsonWriter.WriteNull(System.ReadOnlySpan{System.Byte})> method was called.
3159
+
3158
3160
]]></format>
3159
3161
</remarks>
3160
3162
<exceptioncref="T:System.ArgumentException">The specified property name or value is too large.</exception>
@@ -3415,6 +3417,8 @@ The property name and value are escaped before writing.
3415
3417
3416
3418
The property name and value are escaped before writing.
3417
3419
3420
+
If `value` is `null`, the JSON **null** value is written, as if the <xref:System.Text.Json.Utf8JsonWriter.WriteNull(System.ReadOnlySpan{System.Char})> method was called.
3421
+
3418
3422
]]></format>
3419
3423
</remarks>
3420
3424
<exceptioncref="T:System.ArgumentException">The specified property name or value is too large.</exception>
@@ -3680,6 +3684,8 @@ The property name and value are escaped before writing.
3680
3684
3681
3685
The property name and value are escaped before writing.
3682
3686
3687
+
If `value` is `null`, the JSON **null** value is written, as if the <xref:System.Text.Json.Utf8JsonWriter.WriteNull(System.String)> method was called.
3688
+
3683
3689
]]></format>
3684
3690
</remarks>
3685
3691
<exceptioncref="T:System.ArgumentException">The specified property name or value is too large.</exception>
@@ -3909,6 +3915,8 @@ The property name should already be escaped when the instance of <xref:System.Te
3909
3915
3910
3916
The value is escaped before writing.
3911
3917
3918
+
If `value` is `null`, the JSON **null** value is written, as if the <xref:System.Text.Json.Utf8JsonWriter.WriteNull(System.Text.Json.JsonEncodedText)> method was called.
3919
+
3912
3920
]]></format>
3913
3921
</remarks>
3914
3922
<exceptioncref="T:System.ArgumentException">The specified value is too large.</exception>
@@ -3947,6 +3955,8 @@ The property name should already be escaped when the instance of <xref:System.Te
3947
3955
3948
3956
The value is escaped before writing.
3949
3957
3958
+
If `value` is `null`, the JSON **null** value is written, as if the <xref:System.Text.Json.Utf8JsonWriter.WriteNull(System.Text.Json.JsonEncodedText)> method was called.
3959
+
3950
3960
]]></format>
3951
3961
</remarks>
3952
3962
<exceptioncref="T:System.ArgumentException">The specified value is too large.</exception>
@@ -4185,6 +4195,8 @@ The value is escaped before writing.
4185
4195
4186
4196
The value is escaped before writing.
4187
4197
4198
+
If `value` is `null`, the JSON **null** value is written, as if the <xref:System.Text.Json.Utf8JsonWriter.WriteNullValue> method was called.
4199
+
4188
4200
]]></format>
4189
4201
</remarks>
4190
4202
<exceptioncref="T:System.ArgumentException">The specified value is too large.</exception>
0 commit comments