Skip to content

Commit d434b4c

Browse files
ahsonkhanmairaw
authored andcommitted
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.
1 parent 15d567d commit d434b4c

File tree

3 files changed

+42
-30
lines changed

3 files changed

+42
-30
lines changed

xml/System.Text.Json/JsonReaderOptions.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ By default, the reader throws a <xref:System.Text.Json.JsonException> if it enco
116116
117117
## Remarks
118118
119-
Reading past this depth will throw a <exception cref="T:System.Text.Json.JsonException>.
119+
Reading past this depth will throw a <xref:System.Text.Json.JsonException>.
120120
121121
]]></format>
122122
</remarks>

xml/System.Text.Json/JsonWriterOptions.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Also, <xref:System.Text.Json.Utf8JsonWriter> throws an exception if the user att
4949
</ReturnValue>
5050
<Docs>
5151
<summary>Gets or sets the encoder to use when escaping strings, or <see langword="null" /> to use the default encoder.</summary>
52-
<value>The JavaScript character encoding.</value>
52+
<value>The JavaScript character encoder used to override the escaping behavior.</value>
5353
<remarks>To be added.</remarks>
5454
</Docs>
5555
</Member>

xml/System.Text.Json/Utf8JsonWriter.xml

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
3131
`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.
3232
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.
3434
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.
3636
3737
]]></format>
3838
</remarks>
@@ -55,8 +55,8 @@ To be able to format the output with indentation and white space OR to skip vali
5555
</Parameters>
5656
<Docs>
5757
<param name="bufferWriter">The destination for writing JSON text.</param>
58-
<param name="options">Defines the customized behavior of the <see cref="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 <see cref="T:System.Text.Json.Utf8JsonWriter" /> instance with a specified <see langword="System.Buffers.IBufferWriter&lt;System.Byte&gt;" />.</summary>
58+
<param name="options">Defines the customized behavior of the <see cref="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 <see cref="T:System.Text.Json.Utf8JsonWriter" /> class using the specified <see cref="T:System.Buffers.IBufferWriter`1" /> to write the output to and customization options.</summary>
6060
<remarks>To be added.</remarks>
6161
<exception cref="T:System.ArgumentNullException">
6262
<paramref name="bufferWriter" /> is <see langword="null" />.</exception>
@@ -79,8 +79,8 @@ To be able to format the output with indentation and white space OR to skip vali
7979
</Parameters>
8080
<Docs>
8181
<param name="utf8Json">The destination for writing JSON text.</param>
82-
<param name="options">Defines the customized behavior of the <see cref="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 <see cref="T:System.Text.Json.Utf8JsonWriter" /> instance with a specified <paramref name="utf8Json" />.</summary>
82+
<param name="options">Defines the customized behavior of the <see cref="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 <see cref="T:System.Text.Json.Utf8JsonWriter" /> class using the specified stream to write the output to and customization options.</summary>
8484
<remarks>To be added.</remarks>
8585
<exception cref="T:System.ArgumentNullException">
8686
<paramref name="utf8Json" /> is <see langword="null" />.</exception>
@@ -322,8 +322,8 @@ In the case of <xref:System.IO.Stream>, this writes the data to the stream and f
322322
<ReturnType>System.Text.Json.JsonWriterOptions</ReturnType>
323323
</ReturnValue>
324324
<Docs>
325-
<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 formatting and 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>
327327
<remarks>To be added.</remarks>
328328
</Docs>
329329
</Member>
@@ -383,7 +383,7 @@ The <xref:System.Text.Json.Utf8JsonWriter> will continue to use the original wri
383383
384384
## Remarks
385385
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.
387387
388388
]]></format>
389389
</remarks>
@@ -806,7 +806,7 @@ The property name should already be escaped when the instance of <xref:System.Te
806806
<Parameter Name="utf8Value" Type="System.ReadOnlySpan&lt;System.Byte&gt;" />
807807
</Parameters>
808808
<Docs>
809-
<param name="utf8Value">The UTF-8 encoded value to be written as a JSON comment within /*..*/.</param>
809+
<param name="utf8Value">The UTF-8 encoded value to be written as a JSON comment within `/*..*/`.</param>
810810
<summary>Writes a UTF-8 text value as a JSON comment.</summary>
811811
<remarks>
812812
<format><![CDATA[
@@ -821,7 +821,7 @@ The comment value is not escaped before writing.
821821

822822
-or-
823823

824-
<paramref name="utf8Value" /> contains a comment delimiter (that is, */).</exception>
824+
<paramref name="utf8Value" /> contains a comment delimiter (that is, `*/`).</exception>
825825
</Docs>
826826
</Member>
827827
<Member MemberName="WriteCommentValue">
@@ -843,7 +843,7 @@ The comment value is not escaped before writing.
843843
<Parameter Name="value" Type="System.ReadOnlySpan&lt;System.Char&gt;" />
844844
</Parameters>
845845
<Docs>
846-
<param name="value">The UTF-16 encoded value to be written as a UTF-8 transcoded JSON comment within /*..*/.</param>
846+
<param name="value">The UTF-16 encoded value to be written as a UTF-8 transcoded JSON comment within `/*..*/`.</param>
847847
<summary>Writes a UTF-16 text value as a JSON comment.</summary>
848848
<remarks>
849849
<format><![CDATA[
@@ -854,11 +854,11 @@ The comment value is not escaped before writing.
854854
855855
]]></format>
856856
</remarks>
857-
<exception cref="T:System.ArgumentException">The specified value is too large OR.
857+
<exception cref="T:System.ArgumentException">The specified value is too large.
858858

859859
-or-
860860

861-
<paramref name="value" /> contains a comment delimiter (that is, */).</exception>
861+
<paramref name="value" /> contains a comment delimiter (that is, `*/`).</exception>
862862
</Docs>
863863
</Member>
864864
<Member MemberName="WriteCommentValue">
@@ -880,7 +880,7 @@ The comment value is not escaped before writing.
880880
<Parameter Name="value" Type="System.String" />
881881
</Parameters>
882882
<Docs>
883-
<param name="value">The UTF-16 encoded value to be written as a UTF-8 transcoded JSON comment within /*..*/.</param>
883+
<param name="value">The UTF-16 encoded value to be written as a UTF-8 transcoded JSON comment within `/*..*/`.</param>
884884
<summary>Writes a string text value as a JSON comment.</summary>
885885
<remarks>
886886
<format><![CDATA[
@@ -895,7 +895,7 @@ The comment value is not escaped before writing.
895895

896896
-or-
897897

898-
<paramref name="value" /> contains a comment delimiter (that is, */).</exception>
898+
<paramref name="value" /> contains a comment delimiter (that is, `*/`).</exception>
899899
<exception cref="T:System.ArgumentNullException">The <paramref name="value" /> parameter is <see langword="null" />.</exception>
900900
</Docs>
901901
</Member>
@@ -1167,7 +1167,7 @@ The property name is escaped before writing.
11671167
11681168
## Remarks
11691169
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.
11711171
11721172
The property name is escaped before writing.
11731173
@@ -1281,7 +1281,7 @@ The property name is escaped before writing.
12811281
12821282
## Remarks
12831283
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.
12851285
12861286
The property name is escaped before writing.
12871287
@@ -1443,7 +1443,7 @@ The property name is escaped before writing.
14431443
14441444
## Remarks
14451445
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.
14471447
14481448
The property name is escaped before writing.
14491449
@@ -1557,7 +1557,7 @@ The property name is escaped before writing.
15571557
15581558
## Remarks
15591559
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.
15611561
15621562
The property name is escaped before writing.
15631563
@@ -1720,7 +1720,7 @@ The property name is escaped before writing.
17201720
17211721
## Remarks
17221722
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.
17241724
17251725
The property name is escaped before writing.
17261726
@@ -1837,7 +1837,7 @@ The property name is escaped before writing.
18371837
18381838
## Remarks
18391839
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.
18411841
18421842
The property name is escaped before writing.
18431843
@@ -2001,7 +2001,7 @@ The property name should already be escaped when the instance of <xref:System.Te
20012001
20022002
## Remarks
20032003
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.
20052005
20062006
The property name should already be escaped when the instance of <xref:System.Text.Json.JsonEncodedText> was created.
20072007
@@ -2112,7 +2112,7 @@ The property name should already be escaped when the instance of <xref:System.Te
21122112
21132113
## Remarks
21142114
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.
21162116
21172117
The property name should already be escaped when the instance of <xref:System.Text.Json.JsonEncodedText> was created.
21182118
@@ -2264,7 +2264,7 @@ This method writes the <xref:System.Decimal> value using the default <xref:Syste
22642264
22652265
## Remarks
22662266
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.
22682268
22692269
]]></format>
22702270
</remarks>
@@ -2363,7 +2363,7 @@ This method writes the <xref:System.Int64> value using the default <xref:System.
23632363
23642364
## Remarks
23652365
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.
23672367
23682368
]]></format>
23692369
</remarks>
@@ -2756,7 +2756,7 @@ The property name should already be escaped when the instance of <xref:System.Te
27562756
</remarks>
27572757
<exception cref="T:System.InvalidOperationException">The depth of the JSON has exceeded the maximum depth of 1000.
27582758

2759-
- or -
2759+
-or-
27602760

27612761
Validation is enabled, and this method would result in writing invalid JSON.</exception>
27622762
</Docs>
@@ -2934,7 +2934,7 @@ The property name should already be escaped when the instance of <xref:System.Te
29342934
</remarks>
29352935
<exception cref="T:System.InvalidOperationException">The depth of the JSON has exceeded the maximum depth of 1000.
29362936

2937-
- or -
2937+
-or-
29382938

29392939
Validation is enabled, and this method would result in writing invalid JSON.</exception>
29402940
</Docs>
@@ -3155,6 +3155,8 @@ The property name and value are escaped before writing.
31553155
31563156
The property name and value are escaped before writing.
31573157
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+
31583160
]]></format>
31593161
</remarks>
31603162
<exception cref="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.
34153417
34163418
The property name and value are escaped before writing.
34173419
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+
34183422
]]></format>
34193423
</remarks>
34203424
<exception cref="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.
36803684
36813685
The property name and value are escaped before writing.
36823686
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+
36833689
]]></format>
36843690
</remarks>
36853691
<exception cref="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
39093915
39103916
The value is escaped before writing.
39113917
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+
39123920
]]></format>
39133921
</remarks>
39143922
<exception cref="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
39473955
39483956
The value is escaped before writing.
39493957
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+
39503960
]]></format>
39513961
</remarks>
39523962
<exception cref="T:System.ArgumentException">The specified value is too large.</exception>
@@ -4185,6 +4195,8 @@ The value is escaped before writing.
41854195
41864196
The value is escaped before writing.
41874197
4198+
If `value` is `null`, the JSON **null** value is written, as if the <xref:System.Text.Json.Utf8JsonWriter.WriteNullValue> method was called.
4199+
41884200
]]></format>
41894201
</remarks>
41904202
<exception cref="T:System.ArgumentException">The specified value is too large.</exception>

0 commit comments

Comments
 (0)