-
Notifications
You must be signed in to change notification settings - Fork 4.9k
JsonSerializer.Serialize should check whether the passed-in Utf8JsonWriter is null. #42026
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ public static partial class JsonSerializer | |
/// <param name="writer">The writer to write.</param> | ||
/// <param name="value">The value to convert and write.</param> | ||
/// <param name="options">Options to control the behavior.</param> | ||
/// <exception cref="ArgumentNullException"> | ||
/// <paramref name="writer"/> is null. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @carlossanlop - will your tool pick up changes like these and port to docs or do I have to do it manually? The exception section of the Serialize APIs is a bit light on details currently: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. The tool will pick it up. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A couple of requests:
Like this: <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception> Same request for the exception below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Can we fix this on the docs side? I'll keep the feedback in mind for future updates. Thanks @carlossanlop! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that I think of it, the tool will probably detect the extra spacing and fix it, and will detect the null word and convert it. Let's see if it works. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ahsonkhan I just realized another thing: I don't see this overload in netcore-3.0 in Docs. I pasted the wrong one above (it has 3 parameters). This one has 4 parameters. Has it been sent to Maira via ref assemblies? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We have a generic overload (with 3 args) and the non-generic overload (with 4 args) for serializing into a |
||
/// </exception> | ||
public static void Serialize<TValue>(Utf8JsonWriter writer, TValue value, JsonSerializerOptions options = null) | ||
{ | ||
WriteValueCore(writer, value, typeof(TValue), options); | ||
|
@@ -24,6 +27,9 @@ public static void Serialize<TValue>(Utf8JsonWriter writer, TValue value, JsonSe | |
/// <param name="value">The value to convert and write.</param> | ||
/// <param name="inputType">The type of the <paramref name="value"/> to convert.</param> | ||
/// <param name="options">Options to control the behavior.</param> | ||
/// <exception cref="ArgumentNullException"> | ||
/// <paramref name="writer"/> is null. | ||
/// </exception> | ||
public static void Serialize(Utf8JsonWriter writer, object value, Type inputType, JsonSerializerOptions options = null) | ||
{ | ||
VerifyValueAndType(value, inputType); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be checked here, or in a public method elsewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both public methods call into this method so was following the pattern in the existing code that defers some of the arg validation to the common helper (similar to options/null stream/etc.). Otherwise, I would have done it in the public method.
I left refactoring out of this PR so I can port this change to 3.1.