-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
area-System.Text.Jsonhelp wantedGood for community contributors to help [up-for-grabs]Good for community contributors to help [up-for-grabs]
Milestone
Description
The documentation of the WriteXValue
methods assumes you're calling the method to append a value to a JSON array when there other usecases, for example when writing converters (see here).
namespace SystemTextJsonSamples
{
public class DateTimeOffsetJsonConverter : JsonConverter<DateTimeOffset>
{
public override DateTimeOffset Read(
ref Utf8JsonReader reader,
Type typeToConvert,
JsonSerializerOptions options) =>
DateTimeOffset.ParseExact(reader.GetString()!,
"MM/dd/yyyy", CultureInfo.InvariantCulture);
public override void Write(
Utf8JsonWriter writer,
DateTimeOffset dateTimeValue,
JsonSerializerOptions options) =>
writer.WriteStringValue(dateTimeValue.ToString( // Call to WriteStringValue
"MM/dd/yyyy", CultureInfo.InvariantCulture));
}
}
Documentation for WriteStringValue
:
Writes a string text value (as a JSON string) as an element of a JSON array.
There's also a method call to SetFlagToAddListSeparatorBeforeNextItem()
inside the WriteStringValue(ReadOnlySpan<char> value)
method.
Copilot
Metadata
Metadata
Assignees
Labels
area-System.Text.Jsonhelp wantedGood for community contributors to help [up-for-grabs]Good for community contributors to help [up-for-grabs]