Skip to content

Commit 9eea13d

Browse files
ahsonkhanRon Petrusha
authored andcommitted
Update JsonSerializer docs for clarity. (#3144)
* Update JsonSerializer docs for clarity. * Add back an exception condition for deserializing from the Utf8JsonReader. * Fix parameter name in the remark for the reader overload.
1 parent 239365d commit 9eea13d

File tree

3 files changed

+67
-27
lines changed

3 files changed

+67
-27
lines changed

xml/System.Text.Json/JsonDocumentOptions.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ By default, `AllowTrailingCommas` is set to `false`, and a <xref:System.Text.Jso
8181
8282
## Remarks
8383
84-
By default, a <exception cref="T:System.Text.Json.JsonException> is thrown if a comment is encountered.
84+
By default, a <xref:System.Text.Json.JsonException> is thrown if a comment is encountered.
8585
8686
]]></format>
8787
</remarks>
@@ -116,7 +116,7 @@ By default, a <exception cref="T:System.Text.Json.JsonException> is thrown if a
116116
117117
## Remarks
118118
119-
Parsing past this depth will throw a <exception cref="T:System.Text.Json.JsonException>.
119+
Parsing past this depth will throw a <xref:System.Text.Json.JsonException>.
120120
121121
]]></format>
122122
</remarks>

xml/System.Text.Json/JsonSerializer.xml

Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,15 @@
4646
<remarks>To be added.</remarks>
4747
<exception cref="T:System.ArgumentNullException">
4848
<paramref name="returnType" /> is <see langword="null" />.</exception>
49-
<exception cref="T:System.Text.Json.JsonException">The JSON is invalid, <paramref name="returnType" /> is not compatible with the JSON, or when there is remaining data in the Stream.</exception>
49+
<exception cref="T:System.Text.Json.JsonException">The JSON is invalid.
50+
51+
-or-
52+
53+
<typeparamref name="returnType" /> is not compatible with the JSON.
54+
55+
-or-
56+
57+
There is remaining data in the span beyond a single JSON value.</exception>
5058
</Docs>
5159
</Member>
5260
<Member MemberName="Deserialize">
@@ -86,7 +94,15 @@ UTF-8 methods since the implementation natively uses UTF-8.
8694
</remarks>
8795
<exception cref="T:System.ArgumentNullException">
8896
<paramref name="json" /> or <paramref name="returnType" /> is <see langword="null" />.</exception>
89-
<exception cref="T:System.Text.Json.JsonException">The JSON is invalid, the <paramref name="returnType" /> is not compatible with the JSON, or when there is remaining data in the Stream.</exception>
97+
<exception cref="T:System.Text.Json.JsonException">The JSON is invalid.
98+
99+
-or-
100+
101+
<typeparamref name="TValue" /> is not compatible with the JSON.
102+
103+
-or-
104+
105+
There is remaining data in the string beyond a single JSON value.</exception>
90106
</Docs>
91107
</Member>
92108
<Member MemberName="Deserialize">
@@ -109,7 +125,7 @@ UTF-8 methods since the implementation natively uses UTF-8.
109125
<Parameter Name="options" Type="System.Text.Json.JsonSerializerOptions" />
110126
</Parameters>
111127
<Docs>
112-
<param name="reader">The reader to read.</param>
128+
<param name="reader">The reader to read the JSON from.</param>
113129
<param name="returnType">The type of the object to convert to and return.</param>
114130
<param name="options">Options to control the serializer behavior during reading.</param>
115131
<summary>Reads one JSON value (including objects or arrays) from the provided reader and converts it into an instance of a specified type.</summary>
@@ -131,7 +147,15 @@ The <xref:System.Text.Json.JsonReaderOptions> used to create the instance of the
131147
</remarks>
132148
<exception cref="T:System.ArgumentNullException">
133149
<paramref name="returnType" /> is <see langword="null" />.</exception>
134-
<exception cref="T:System.Text.Json.JsonException">The JSON is invalid, <paramref name="returnType" /> is not compatible with the JSON, or a value could not be read from the reader.</exception>
150+
<exception cref="T:System.Text.Json.JsonException">The JSON is invalid.
151+
152+
-or-
153+
154+
<typeparamref name="returnType" /> is not compatible with the JSON.
155+
156+
-or-
157+
158+
A value could not be read from the reader.</exception>
135159
<exception cref="T:System.ArgumentException">
136160
<paramref name="reader" /> is using unsupported options.</exception>
137161
</Docs>
@@ -172,7 +196,7 @@ The <xref:System.Text.Json.JsonReaderOptions> used to create the instance of the
172196

173197
-or-
174198

175-
There is remaining data in the stream.</exception>
199+
There is remaining data in the span beyond a single JSON value.</exception>
176200
</Docs>
177201
</Member>
178202
<Member MemberName="Deserialize&lt;TValue&gt;">
@@ -220,7 +244,7 @@ Using a <xref:System.String> is not as efficient as using the UTF-8 methods sinc
220244

221245
-or-
222246

223-
There is remaining data in the stream.</exception>
247+
There is remaining data in the string beyond a single JSON value.</exception>
224248
</Docs>
225249
</Member>
226250
<Member MemberName="Deserialize&lt;TValue&gt;">
@@ -246,7 +270,7 @@ There is remaining data in the stream.</exception>
246270
</Parameters>
247271
<Docs>
248272
<typeparam name="TValue">The target type of the JSON value.</typeparam>
249-
<param name="reader">The reader to read.</param>
273+
<param name="reader">The reader to read the JSON from.</param>
250274
<param name="options">Options to control serializer behavior during reading.</param>
251275
<summary>Reads one JSON value (including objects or arrays) from the provided reader into an instance of the type specified by a generic type parameter.</summary>
252276
<returns>A <typeparamref name="TValue" /> representation of the JSON value.</returns>
@@ -273,7 +297,7 @@ The <xref:System.Text.Json.JsonReaderOptions> used to create the instance of the
273297

274298
-or-
275299

276-
There is remaining data in the stream.</exception>
300+
A value could not be read from the reader.</exception>
277301
<exception cref="T:System.ArgumentException">
278302
<paramref name="reader" /> uses unsupported options.</exception>
279303
</Docs>
@@ -381,8 +405,8 @@ There is remaining data in the stream.</exception>
381405
<param name="value">The value to convert.</param>
382406
<param name="inputType">The type of the <paramref name="value" /> to convert.</param>
383407
<param name="options">Options to control the conversion behavior.</param>
384-
<summary>Converts the value of a specified type into a <see cref="T:System.String" />.</summary>
385-
<returns>The string representation of the value.</returns>
408+
<summary>Converts the value of a specified type into a JSON string.</summary>
409+
<returns>The JSON string representation of the value.</returns>
386410
<remarks>
387411
<format type="text/markdown"><![CDATA[
388412
@@ -415,12 +439,20 @@ Using a <xref:System.String> is not as efficient as using UTF-8 encoding since t
415439
<Parameter Name="options" Type="System.Text.Json.JsonSerializerOptions" />
416440
</Parameters>
417441
<Docs>
418-
<param name="writer">The JSON writer.</param>
442+
<param name="writer">The JSON writer to write to.</param>
419443
<param name="value">The value to convert and write.</param>
420444
<param name="inputType">The type of the <paramref name="value" /> to convert.</param>
421445
<param name="options">Options to control serialization behavior.</param>
422-
<summary>Writes one JSON value (including objects or arrays) of a specified type to the provided writer.</summary>
423-
<remarks>To be added.</remarks>
446+
<summary>Writes the JSON representation of the specified type to the provided writer.</summary>
447+
<remarks>
448+
<format type="text/markdown"><![CDATA[
449+
450+
## Remarks
451+
452+
The <xref:System.Text.Json.JsonWriterOptions> used to create the instance of the <xref:System.Text.Json.Utf8JsonWriter> take precedence over the <xref:System.Text.Json.JsonSerializerOptions> when they conflict. Hence, <xref:System.Text.Json.JsonWriterOptions.Indented?displayProperty=nameWithType>, <xref:System.Text.Json.JsonWriterOptions.SkipValidation?displayProperty=nameWithType>, and <xref:System.Text.Json.JsonWriterOptions.Encoder?displayProperty=nameWithType> are used while writing.
453+
454+
]]></format>
455+
</remarks>
424456
</Docs>
425457
</Member>
426458
<Member MemberName="Serialize&lt;TValue&gt;">
@@ -448,8 +480,8 @@ Using a <xref:System.String> is not as efficient as using UTF-8 encoding since t
448480
<typeparam name="TValue">The type of the value to serialize.</typeparam>
449481
<param name="value">The value to convert.</param>
450482
<param name="options">Options to control serialization behavior.</param>
451-
<summary>Converts the value of a type specified by a generic type parameter into a <see cref="T:System.String" />.</summary>
452-
<returns>A string representation of the value.</returns>
483+
<summary>Converts the value of a type specified by a generic type parameter into a JSON string.</summary>
484+
<returns>A JSON string representation of the value.</returns>
453485
<remarks>
454486
<format type="text/markdown"><![CDATA[
455487
@@ -485,11 +517,19 @@ Using a <xref:System.String> is not as efficient as using UTF-8 encoding since t
485517
</Parameters>
486518
<Docs>
487519
<typeparam name="TValue">The type of the value to serialize.</typeparam>
488-
<param name="writer">A JSON writer.</param>
520+
<param name="writer">A JSON writer to write to.</param>
489521
<param name="value">The value to convert and write.</param>
490522
<param name="options">Options to control serialization behavior.</param>
491-
<summary>Writes one JSON value (including objects or arrays) of a type specified by a generic type parameter to the provided writer.</summary>
492-
<remarks>To be added.</remarks>
523+
<summary>Writes the JSON representation of a type specified by a generic type parameter to the provided writer.</summary>
524+
<remarks>
525+
<format type="text/markdown"><![CDATA[
526+
527+
## Remarks
528+
529+
The <xref:System.Text.Json.JsonWriterOptions> used to create the instance of the <xref:System.Text.Json.Utf8JsonWriter> take precedence over the <xref:System.Text.Json.JsonSerializerOptions> when they conflict. Hence, <xref:System.Text.Json.JsonWriterOptions.Indented?displayProperty=nameWithType>, <xref:System.Text.Json.JsonWriterOptions.SkipValidation?displayProperty=nameWithType>, and <xref:System.Text.Json.JsonWriterOptions.Encoder?displayProperty=nameWithType> are used while writing.
530+
531+
]]></format>
532+
</remarks>
493533
</Docs>
494534
</Member>
495535
<Member MemberName="SerializeAsync">
@@ -579,8 +619,8 @@ Using a <xref:System.String> is not as efficient as using UTF-8 encoding since t
579619
<param name="value">The value to convert.</param>
580620
<param name="inputType">The type of the <paramref name="value" /> to convert.</param>
581621
<param name="options">Options to control the conversion behavior.</param>
582-
<summary>Converts a value of the specified type into a UTF8-encoded byte array.</summary>
583-
<returns>A UTF-8 representation of the value.</returns>
622+
<summary>Converts a value of the specified type into a JSON string, encoded as UTF-8 bytes.</summary>
623+
<returns>A JSON string representation of the value, encoded as UTF-8 bytes.</returns>
584624
<remarks>To be added.</remarks>
585625
</Docs>
586626
</Member>
@@ -609,8 +649,8 @@ Using a <xref:System.String> is not as efficient as using UTF-8 encoding since t
609649
<typeparam name="TValue">The type of the value.</typeparam>
610650
<param name="value">The value to convert.</param>
611651
<param name="options">Options to control the conversion behavior.</param>
612-
<summary>Converts the value of a type specifed by a generic type parameter into a UTF8-encoded byte array.</summary>
613-
<returns>A UTF-8 representation of the value.</returns>
652+
<summary>Converts the value of a type specifed by a generic type parameter into a JSON string, encoded as UTF-8 bytes.</summary>
653+
<returns>A JSON string representation of the value, encoded as UTF-8 bytes.</returns>
614654
<remarks>To be added.</remarks>
615655
</Docs>
616656
</Member>

xml/System.Text.Json/JsonValueKind.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
</ReturnValue>
5555
<MemberValue>6</MemberValue>
5656
<Docs>
57-
<summary>Indicates that a value is the JSON value <see langword="false" />.</summary>
57+
<summary>The JSON value <b>false</b>.</summary>
5858
</Docs>
5959
</Member>
6060
<Member MemberName="Null">
@@ -74,7 +74,7 @@
7474
</ReturnValue>
7575
<MemberValue>7</MemberValue>
7676
<Docs>
77-
<summary>The JSON value <see langword="null" />.</summary>
77+
<summary>The JSON value <b>null</b>.</summary>
7878
</Docs>
7979
</Member>
8080
<Member MemberName="Number">
@@ -154,7 +154,7 @@
154154
</ReturnValue>
155155
<MemberValue>5</MemberValue>
156156
<Docs>
157-
<summary>The JSON value <see langword="true" />.</summary>
157+
<summary>The JSON value <b>true</b>.</summary>
158158
</Docs>
159159
</Member>
160160
<Member MemberName="Undefined">

0 commit comments

Comments
 (0)