Change (string)null behaviors in Utf8JsonWriter
authorJeremy Barton <jbarton@microsoft.com>
Sat, 13 Jul 2019 14:20:12 +0000 (07:20 -0700)
committerGitHub <noreply@github.com>
Sat, 13 Jul 2019 14:20:12 +0000 (07:20 -0700)
commit10aa9f3364c0003028217f7260de932d92a7e7ed
treeeb6d0045e19fd9eaba07b2467756932363bca16a
parent03a36223e97c53b3d5dca67bd79de1e8bd88663d
Change (string)null behaviors in Utf8JsonWriter

ArgumentNullException when used as a property name, empty string
as a property name if it's already in ReadOnlySpan<char>.

* WriteNull(string)
* WriteBoolean(string, bool)
* WriteNumber(string, *)
* WriteString(string, *)
* WriteStartArray(string)
* WriteStartObject(string)
* WritePropertyName(string)

Emits the null literal (vs the empty string):

* WriteStringValue(string)
* WriteString(*, string)

Since the writer will write null via WriteStringValue, the reader GetString()
now will return null if TokenType is null (matches JsonElement behavior).

Commit migrated from https://github.com/dotnet/corefx/commit/adce92338911eec22e5c8f9f071ece857de7d624
19 files changed:
src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.TryGet.cs
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Bytes.cs
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.DateTime.cs
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.DateTimeOffset.cs
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Decimal.cs
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Double.cs
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Float.cs
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Guid.cs
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Literal.cs
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.SignedNumber.cs
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.String.cs
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.UnsignedNumber.cs
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Comment.cs
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.String.cs
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.cs
src/libraries/System.Text.Json/tests/Serialization/Value.WriteTests.cs
src/libraries/System.Text.Json/tests/Utf8JsonReaderTests.TryGet.cs
src/libraries/System.Text.Json/tests/Utf8JsonReaderTests.cs
src/libraries/System.Text.Json/tests/Utf8JsonWriterTests.cs