Skip to content

Fix Utf8JsonWriter WriteXValue methods documentation to remove array-specific language #11476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 19, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 19, 2025

The WriteXValue methods in Utf8JsonWriter had documentation that incorrectly stated they write values "as an element of a JSON array". However, these methods can be used in various contexts, not just arrays:

  • As array elements: [value1, value2, value3]
  • As object property values: {"property": value}
  • As standalone JSON values (e.g., in custom converters)

Example from the issue

The problem was evident in custom converters like this:

public override void Write(
    Utf8JsonWriter writer,
    DateTimeOffset dateTimeValue,
    JsonSerializerOptions options) =>
        writer.WriteStringValue(dateTimeValue.ToString( // Not writing to an array!
            "MM/dd/yyyy", CultureInfo.InvariantCulture));

Changes made

Updated documentation for all affected WriteXValue methods to remove the misleading "as an element of a JSON array" language:

  • WriteStringValue (all overloads): DateTime, DateTimeOffset, Guid, ReadOnlySpan<byte>, ReadOnlySpan<char>, string, JsonEncodedText
  • WriteBooleanValue
  • WriteNullValue
  • WriteNumberValue (all numeric types): Decimal, Double, Int32, Int64, Single, UInt32, UInt64
  • WriteBase64StringValue

Before and after

Before:

<summary>Writes a string text value (as a JSON string) as an element of a JSON array.</summary>

After:

<summary>Writes a string text value (as a JSON string).</summary>

The documentation now accurately reflects that these methods write JSON values in any valid context, not just arrays.

Fixes #11360.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: jeffhandley <1031940+jeffhandley@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Utf8JsonWriter WriteXValue methods assume an array is being written to Fix Utf8JsonWriter WriteXValue methods documentation to remove array-specific language Jun 19, 2025
Copilot finished work on behalf of jeffhandley June 19, 2025 06:51
@Copilot Copilot AI requested a review from jeffhandley June 19, 2025 06:51
@jeffhandley jeffhandley marked this pull request as ready for review June 19, 2025 07:07
@jeffhandley jeffhandley requested a review from a team as a code owner June 19, 2025 07:07
@gewarren gewarren merged commit 6339fca into main Jun 19, 2025
8 checks passed
@gewarren gewarren deleted the copilot/fix-11360 branch June 19, 2025 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Utf8JsonWriter WriteXValue methods assume an array is being written to
4 participants