From 5b4f3b05585df7735dc3bdc28d27f18811c3e18f Mon Sep 17 00:00:00 2001 From: Ahson Khan Date: Wed, 26 Jun 2019 11:58:52 -0700 Subject: [PATCH] Rename JsonValueType to JsonValueKind and JsonElement.Type to JsonElement.ValueKind. (dotnet/corefx#38943) * Add JsonDocument.Write, JsonProperty.Write, and rename JsonValueTupe to JsonValueKind. * Add JsonDocument.Write API tests. * Don't use GetPropertyRawBytes and add JsonProperty.Write API tests. * Make GetPropertyRawValue private again. * Remove the new Write APIs on JsonDocument, JsonProperty. Commit migrated from https://github.com/dotnet/corefx/commit/f08256cbba2b249cc1e5ca67cf4a1c074adf035b --- .../System.Text.Json/ref/System.Text.Json.cs | 4 +- .../System.Text.Json/src/System.Text.Json.csproj | 2 +- .../src/System/Text/Json/Document/JsonElement.cs | 118 ++++++++++----------- .../src/System/Text/Json/Document/JsonProperty.cs | 2 +- .../{JsonValueType.cs => JsonValueKind.cs} | 2 +- .../System/Text/Json/Reader/JsonReaderHelper.cs | 12 +-- .../src/System/Text/Json/ThrowHelper.cs | 4 +- .../System.Text.Json/tests/JsonDocumentTests.cs | 104 +++++++++--------- .../tests/JsonElementCloneTests.cs | 18 ++-- .../tests/Serialization/DictionaryTests.cs | 4 +- .../tests/Serialization/ExtensionDataTests.cs | 16 +-- .../tests/Serialization/JsonElementTests.cs | 30 +++--- .../tests/Serialization/Object.ReadTests.cs | 14 +-- .../tests/Serialization/PolymorphicTests.cs | 6 +- .../tests/Serialization/SpanTests.cs | 2 +- .../TestClasses.SimpleTestClassWithObjectArrays.cs | 38 +++---- .../TestClasses.SimpleTestClassWithSimpleObject.cs | 36 +++---- .../tests/TestClasses.ClassWithComplexObjects.cs | 12 +-- 18 files changed, 212 insertions(+), 212 deletions(-) rename src/libraries/System.Text.Json/src/System/Text/Json/Document/{JsonValueType.cs => JsonValueKind.cs} (97%) diff --git a/src/libraries/System.Text.Json/ref/System.Text.Json.cs b/src/libraries/System.Text.Json/ref/System.Text.Json.cs index 4989200..3781b73 100644 --- a/src/libraries/System.Text.Json/ref/System.Text.Json.cs +++ b/src/libraries/System.Text.Json/ref/System.Text.Json.cs @@ -39,7 +39,7 @@ namespace System.Text.Json private readonly object _dummy; private readonly int _dummyPrimitive; public System.Text.Json.JsonElement this[int index] { get { throw null; } } - public System.Text.Json.JsonValueType Type { get { throw null; } } + public System.Text.Json.JsonValueKind ValueKind { get { throw null; } } public System.Text.Json.JsonElement Clone() { throw null; } public System.Text.Json.JsonElement.ArrayEnumerator EnumerateArray() { throw null; } public System.Text.Json.JsonElement.ObjectEnumerator EnumerateObject() { throw null; } @@ -233,7 +233,7 @@ namespace System.Text.Json Null = (byte)10, Comment = (byte)11, } - public enum JsonValueType : byte + public enum JsonValueKind : byte { Undefined = (byte)0, Object = (byte)1, diff --git a/src/libraries/System.Text.Json/src/System.Text.Json.csproj b/src/libraries/System.Text.Json/src/System.Text.Json.csproj index 8c6108e..a8f9c63 100644 --- a/src/libraries/System.Text.Json/src/System.Text.Json.csproj +++ b/src/libraries/System.Text.Json/src/System.Text.Json.csproj @@ -40,7 +40,7 @@ - + diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonElement.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonElement.cs index 4188ac3..214eaab 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonElement.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonElement.cs @@ -30,19 +30,19 @@ namespace System.Text.Json private JsonTokenType TokenType => _parent?.GetJsonTokenType(_idx) ?? JsonTokenType.None; /// - /// The that the value is. + /// The that the value is. /// /// /// The parent has been disposed. /// - public JsonValueType Type => TokenType.ToValueType(); + public JsonValueKind ValueKind => TokenType.ToValueKind(); /// /// Get the value at a specified index when the current value is a - /// . + /// . /// /// - /// This value's is not . + /// This value's is not . /// /// /// is not in the range [0, ()). @@ -65,7 +65,7 @@ namespace System.Text.Json /// /// The number of values contained within the current array value. /// - /// This value's is not . + /// This value's is not . /// /// /// The parent has been disposed. @@ -93,7 +93,7 @@ namespace System.Text.Json /// /// /// - /// This value's is not . + /// This value's is not . /// /// /// No property was found with the requested name. @@ -137,7 +137,7 @@ namespace System.Text.Json /// /// /// - /// This value's is not . + /// This value's is not . /// /// /// No property was found with the requested name. @@ -176,7 +176,7 @@ namespace System.Text.Json /// A representing the value of the requested property. /// /// - /// This value's is not . + /// This value's is not . /// /// /// No property was found with the requested name. @@ -216,7 +216,7 @@ namespace System.Text.Json /// if the property was found, otherwise. /// /// - /// This value's is not . + /// This value's is not . /// /// /// is . @@ -255,7 +255,7 @@ namespace System.Text.Json /// /// /// - /// This value's is not . + /// This value's is not . /// /// /// The parent has been disposed. @@ -291,7 +291,7 @@ namespace System.Text.Json /// /// /// - /// This value's is not . + /// This value's is not . /// /// /// The parent has been disposed. @@ -311,8 +311,8 @@ namespace System.Text.Json /// /// The value of the element as a . /// - /// This value's is neither or - /// . + /// This value's is neither or + /// . /// /// /// The parent has been disposed. @@ -338,7 +338,7 @@ namespace System.Text.Json /// /// The value of the element as a . /// - /// This value's is neither nor . + /// This value's is neither nor . /// /// /// The parent has been disposed. @@ -363,7 +363,7 @@ namespace System.Text.Json /// otherwise. /// /// - /// This value's is not . + /// This value's is not . /// /// /// The parent has been disposed. @@ -383,7 +383,7 @@ namespace System.Text.Json /// /// The value decode to bytes. /// - /// This value's is not . + /// This value's is not . /// /// /// The value is not encoded as base 64 text and hence cannot be decoded to bytes. @@ -414,7 +414,7 @@ namespace System.Text.Json /// otherwise. /// /// - /// This value's is not . + /// This value's is not . /// /// /// The parent has been disposed. @@ -432,7 +432,7 @@ namespace System.Text.Json /// /// The current JSON number as an . /// - /// This value's is not . + /// This value's is not . /// /// /// The value cannot be represented as an . @@ -463,7 +463,7 @@ namespace System.Text.Json /// otherwise. /// /// - /// This value's is not . + /// This value's is not . /// /// /// The parent has been disposed. @@ -483,7 +483,7 @@ namespace System.Text.Json /// This method does not parse the contents of a JSON string value. /// /// - /// This value's is not . + /// This value's is not . /// /// /// The value cannot be represented as a . @@ -513,7 +513,7 @@ namespace System.Text.Json /// otherwise. /// /// - /// This value's is not . + /// This value's is not . /// /// /// The parent has been disposed. @@ -530,7 +530,7 @@ namespace System.Text.Json /// /// The current JSON number as an . /// - /// This value's is not . + /// This value's is not . /// /// /// The value cannot be represented as an . @@ -560,7 +560,7 @@ namespace System.Text.Json /// otherwise. /// /// - /// This value's is not . + /// This value's is not . /// /// /// The parent has been disposed. @@ -581,7 +581,7 @@ namespace System.Text.Json /// This method does not parse the contents of a JSON string value. /// /// - /// This value's is not . + /// This value's is not . /// /// /// The value cannot be represented as a . @@ -612,7 +612,7 @@ namespace System.Text.Json /// otherwise. /// /// - /// This value's is not . + /// This value's is not . /// /// /// The parent has been disposed. @@ -629,7 +629,7 @@ namespace System.Text.Json /// /// The current JSON number as an . /// - /// This value's is not . + /// This value's is not . /// /// /// The value cannot be represented as an . @@ -659,7 +659,7 @@ namespace System.Text.Json /// otherwise. /// /// - /// This value's is not . + /// This value's is not . /// /// /// The parent has been disposed. @@ -680,7 +680,7 @@ namespace System.Text.Json /// This method does not parse the contents of a JSON string value. /// /// - /// This value's is not . + /// This value's is not . /// /// /// The value cannot be represented as a . @@ -711,7 +711,7 @@ namespace System.Text.Json /// otherwise. /// /// - /// This value's is not . + /// This value's is not . /// /// /// The parent has been disposed. @@ -731,7 +731,7 @@ namespace System.Text.Json /// This method does not parse the contents of a JSON string value. /// /// - /// This value's is not . + /// This value's is not . /// /// /// The value cannot be represented as a . @@ -761,7 +761,7 @@ namespace System.Text.Json /// otherwise. /// /// - /// This value's is not . + /// This value's is not . /// /// /// The parent has been disposed. @@ -782,7 +782,7 @@ namespace System.Text.Json /// This method does not parse the contents of a JSON string value. /// /// - /// This value's is not . + /// This value's is not . /// /// /// The value cannot be represented as a . @@ -822,7 +822,7 @@ namespace System.Text.Json /// otherwise. /// /// - /// This value's is not . + /// This value's is not . /// /// /// The parent has been disposed. @@ -850,7 +850,7 @@ namespace System.Text.Json /// /// /// - /// This value's is not . + /// This value's is not . /// /// /// The value cannot be represented as a . @@ -889,7 +889,7 @@ namespace System.Text.Json /// otherwise. /// /// - /// This value's is not . + /// This value's is not . /// /// /// The parent has been disposed. @@ -917,7 +917,7 @@ namespace System.Text.Json /// /// /// - /// This value's is not . + /// This value's is not . /// /// /// The value cannot be represented as a . @@ -947,7 +947,7 @@ namespace System.Text.Json /// otherwise. /// /// - /// This value's is not . + /// This value's is not . /// /// /// The parent has been disposed. @@ -968,7 +968,7 @@ namespace System.Text.Json /// This method does not parse the contents of a JSON string value. /// /// - /// This value's is not . + /// This value's is not . /// /// /// The value cannot be represented as a . @@ -999,7 +999,7 @@ namespace System.Text.Json /// otherwise. /// /// - /// This value's is not . + /// This value's is not . /// /// /// The parent has been disposed. @@ -1019,7 +1019,7 @@ namespace System.Text.Json /// /// The value of the element as a . /// - /// This value's is not . + /// This value's is not . /// /// /// The value cannot be represented as a . @@ -1050,7 +1050,7 @@ namespace System.Text.Json /// otherwise. /// /// - /// This value's is not . + /// This value's is not . /// /// /// The parent has been disposed. @@ -1070,7 +1070,7 @@ namespace System.Text.Json /// /// The value of the element as a . /// - /// This value's is not . + /// This value's is not . /// /// /// The value cannot be represented as a . @@ -1101,7 +1101,7 @@ namespace System.Text.Json /// otherwise. /// /// - /// This value's is not . + /// This value's is not . /// /// /// The parent has been disposed. @@ -1121,7 +1121,7 @@ namespace System.Text.Json /// /// The value of the element as a . /// - /// This value's is not . + /// This value's is not . /// /// /// The value cannot be represented as a . @@ -1179,7 +1179,7 @@ namespace System.Text.Json /// otherwise. /// /// - /// This value's is not . + /// This value's is not . /// /// /// This method is functionally equal to doing an ordinal comparison of and @@ -1206,7 +1206,7 @@ namespace System.Text.Json /// , otherwise. /// /// - /// This value's is not . + /// This value's is not . /// /// /// This method is functionally equal to doing an ordinal comparison of the string produced by UTF-8 decoding @@ -1235,7 +1235,7 @@ namespace System.Text.Json /// otherwise. /// /// - /// This value's is not . + /// This value's is not . /// /// /// This method is functionally equal to doing an ordinal comparison of and @@ -1274,7 +1274,7 @@ namespace System.Text.Json /// The name for this value within the JSON object. /// The writer. /// - /// This value's is . + /// This value's is . /// /// /// The parent has been disposed. @@ -1288,7 +1288,7 @@ namespace System.Text.Json /// The name for this value within the JSON object. /// The writer. /// - /// This value's is . + /// This value's is . /// /// /// The parent has been disposed. @@ -1306,7 +1306,7 @@ namespace System.Text.Json /// The pre-encoded name for this value within the JSON object. /// The writer. /// - /// This value's is . + /// This value's is . /// /// /// The parent has been disposed. @@ -1326,7 +1326,7 @@ namespace System.Text.Json /// /// The writer. /// - /// This value's is . + /// This value's is . /// /// /// The parent has been disposed. @@ -1343,7 +1343,7 @@ namespace System.Text.Json /// /// The writer. /// - /// This value's is . + /// This value's is . /// /// /// The parent has been disposed. @@ -1362,7 +1362,7 @@ namespace System.Text.Json /// An enumerator to enumerate the values in the JSON array represented by this JsonElement. /// /// - /// This value's is not . + /// This value's is not . /// /// /// The parent has been disposed. @@ -1388,7 +1388,7 @@ namespace System.Text.Json /// An enumerator to enumerate the properties in the JSON object represented by this JsonElement. /// /// - /// This value's is not . + /// This value's is not . /// /// /// The parent has been disposed. @@ -1412,19 +1412,19 @@ namespace System.Text.Json /// /// /// - /// For , is returned. + /// For , is returned. /// /// /// - /// For , is returned. + /// For , is returned. /// /// /// - /// For , is returned. + /// For , is returned. /// /// /// - /// For , the value of () is returned. + /// For , the value of () is returned. /// /// /// @@ -1501,6 +1501,6 @@ namespace System.Text.Json } [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private string DebuggerDisplay => $"Type = {Type} : \"{ToString()}\""; + private string DebuggerDisplay => $"ValueKind = {ValueKind} : \"{ToString()}\""; } } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonProperty.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonProperty.cs index 4b999a5..fcab3e9 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonProperty.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonProperty.cs @@ -103,6 +103,6 @@ namespace System.Text.Json } private string DebuggerDisplay - => Value.Type == JsonValueType.Undefined ? "" : $"\"{ToString()}\""; + => Value.ValueKind == JsonValueKind.Undefined ? "" : $"\"{ToString()}\""; } } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonValueType.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonValueKind.cs similarity index 97% rename from src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonValueType.cs rename to src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonValueKind.cs index 18240bc..ae63208 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonValueType.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonValueKind.cs @@ -7,7 +7,7 @@ namespace System.Text.Json /// /// Specifies the data type of a JSON value. /// - public enum JsonValueType : byte + public enum JsonValueKind : byte { /// /// Indicates that there is no value (as distinct from ). diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderHelper.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderHelper.cs index e8bd2b7..a4b3f55 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderHelper.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderHelper.cs @@ -28,25 +28,25 @@ namespace System.Text.Json return (newLines, lastLineFeedIndex); } - internal static JsonValueType ToValueType(this JsonTokenType tokenType) + internal static JsonValueKind ToValueKind(this JsonTokenType tokenType) { switch (tokenType) { case JsonTokenType.None: - return JsonValueType.Undefined; + return JsonValueKind.Undefined; case JsonTokenType.StartArray: - return JsonValueType.Array; + return JsonValueKind.Array; case JsonTokenType.StartObject: - return JsonValueType.Object; + return JsonValueKind.Object; case JsonTokenType.String: case JsonTokenType.Number: case JsonTokenType.True: case JsonTokenType.False: case JsonTokenType.Null: - return (JsonValueType)((byte)tokenType - 3); + return (JsonValueKind)((byte)tokenType - 3); default: Debug.Fail($"No mapping for token type {tokenType}"); - return JsonValueType.Undefined; + return JsonValueKind.Undefined; } } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/ThrowHelper.cs b/src/libraries/System.Text.Json/src/System/Text/Json/ThrowHelper.cs index 73279c9..0b69fcf 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/ThrowHelper.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/ThrowHelper.cs @@ -232,7 +232,7 @@ namespace System.Text.Json JsonTokenType actualType) { return GetInvalidOperationException( - SR.Format(SR.JsonElementHasWrongType, expectedType.ToValueType(), actualType.ToValueType())); + SR.Format(SR.JsonElementHasWrongType, expectedType.ToValueKind(), actualType.ToValueKind())); } [MethodImpl(MethodImplOptions.NoInlining)] @@ -241,7 +241,7 @@ namespace System.Text.Json JsonTokenType actualType) { return GetInvalidOperationException( - SR.Format(SR.JsonElementHasWrongType, expectedTypeName, actualType.ToValueType())); + SR.Format(SR.JsonElementHasWrongType, expectedTypeName, actualType.ToValueKind())); } public static void ThrowJsonReaderException(ref Utf8JsonReader json, ExceptionResource resource, byte nextByte = default, ReadOnlySpan bytes = default) diff --git a/src/libraries/System.Text.Json/tests/JsonDocumentTests.cs b/src/libraries/System.Text.Json/tests/JsonDocumentTests.cs index 9610705..60d372d 100644 --- a/src/libraries/System.Text.Json/tests/JsonDocumentTests.cs +++ b/src/libraries/System.Text.Json/tests/JsonDocumentTests.cs @@ -314,7 +314,7 @@ namespace System.Text.Json.Tests using (JsonDocument doc = JsonDocument.Parse(new MemoryStream(data))) { JsonElement root = doc.RootElement; - Assert.Equal(JsonValueType.Number, root.Type); + Assert.Equal(JsonValueKind.Number, root.ValueKind); Assert.Equal(11, root.GetInt32()); } } @@ -328,7 +328,7 @@ namespace System.Text.Json.Tests JsonDocument.Parse(new WrappedMemoryStream(canRead: true, canWrite: false, canSeek: false, data: data))) { JsonElement root = doc.RootElement; - Assert.Equal(JsonValueType.Number, root.Type); + Assert.Equal(JsonValueKind.Number, root.ValueKind); Assert.Equal(11, root.GetInt32()); } } @@ -341,7 +341,7 @@ namespace System.Text.Json.Tests using (JsonDocument doc = await JsonDocument.ParseAsync(new MemoryStream(data))) { JsonElement root = doc.RootElement; - Assert.Equal(JsonValueType.Number, root.Type); + Assert.Equal(JsonValueKind.Number, root.ValueKind); Assert.Equal(11, root.GetInt32()); } } @@ -355,7 +355,7 @@ namespace System.Text.Json.Tests new WrappedMemoryStream(canRead: true, canWrite: false, canSeek: false, data: data))) { JsonElement root = doc.RootElement; - Assert.Equal(JsonValueType.Number, root.Type); + Assert.Equal(JsonValueKind.Number, root.ValueKind); Assert.Equal(11, root.GetInt32()); } } @@ -554,20 +554,20 @@ namespace System.Text.Json.Tests private static void DepthFirstAppend(StringBuilder buf, JsonElement element) { - JsonValueType type = element.Type; + JsonValueKind kind = element.ValueKind; - switch (type) + switch (kind) { - case JsonValueType.False: - case JsonValueType.True: - case JsonValueType.String: - case JsonValueType.Number: + case JsonValueKind.False: + case JsonValueKind.True: + case JsonValueKind.String: + case JsonValueKind.Number: { buf.Append(element.ToString()); buf.Append(", "); break; } - case JsonValueType.Object: + case JsonValueKind.Object: { foreach (JsonProperty prop in element.EnumerateObject()) { @@ -578,7 +578,7 @@ namespace System.Text.Json.Tests break; } - case JsonValueType.Array: + case JsonValueKind.Array: { foreach (JsonElement child in element.EnumerateArray()) { @@ -727,7 +727,7 @@ namespace System.Text.Json.Tests { JsonElement root = doc.RootElement; - Assert.Equal(JsonValueType.Array, root.Type); + Assert.Equal(JsonValueKind.Array, root.ValueKind); Assert.Equal(SR.ParseJson, root.ToString()); } } @@ -739,7 +739,7 @@ namespace System.Text.Json.Tests { JsonElement root = doc.RootElement; - Assert.Equal(JsonValueType.Object, root.Type); + Assert.Equal(JsonValueKind.Object, root.ValueKind); Assert.Equal(SR.BasicJson, root.ToString()); } } @@ -768,7 +768,7 @@ namespace System.Text.Json.Tests Assert.Equal("425-214-3151", phoneNumber); Assert.Equal(25, age); - Assert.Equal(JsonValueType.Null, root[3].Type); + Assert.Equal(JsonValueKind.Null, root[3].ValueKind); Assert.Throws(() => root[4]); } @@ -788,7 +788,7 @@ namespace System.Text.Json.Tests { JsonElement root = doc.RootElement; - Assert.Equal(JsonValueType.Number, root.Type); + Assert.Equal(JsonValueKind.Number, root.ValueKind); Assert.True(root.TryGetSingle(out float floatVal)); Assert.Equal(expectedFloat, floatVal); @@ -888,7 +888,7 @@ namespace System.Text.Json.Tests { JsonElement root = doc.RootElement; - Assert.Equal(JsonValueType.Number, root.Type); + Assert.Equal(JsonValueKind.Number, root.ValueKind); Assert.True(root.TryGetSingle(out float floatVal)); Assert.Equal(expectedFloat, floatVal); @@ -985,7 +985,7 @@ namespace System.Text.Json.Tests { JsonElement root = doc.RootElement; - Assert.Equal(JsonValueType.Number, root.Type); + Assert.Equal(JsonValueKind.Number, root.ValueKind); Assert.True(root.TryGetSingle(out float floatVal)); Assert.Equal(expectedFloat, floatVal); @@ -1079,7 +1079,7 @@ namespace System.Text.Json.Tests { JsonElement root = doc.RootElement; - Assert.Equal(JsonValueType.Number, root.Type); + Assert.Equal(JsonValueKind.Number, root.ValueKind); Assert.True(root.TryGetSingle(out float floatVal)); Assert.Equal(expectedFloat, floatVal); @@ -1179,7 +1179,7 @@ namespace System.Text.Json.Tests { JsonElement root = doc.RootElement; - Assert.Equal(JsonValueType.Number, root.Type); + Assert.Equal(JsonValueKind.Number, root.ValueKind); Assert.True(root.TryGetSingle(out float floatVal)); Assert.Equal(expectedFloat, floatVal); @@ -1253,7 +1253,7 @@ namespace System.Text.Json.Tests { JsonElement root = doc.RootElement; - Assert.Equal(JsonValueType.Number, root.Type); + Assert.Equal(JsonValueKind.Number, root.ValueKind); Assert.True(root.TryGetSingle(out float floatVal)); Assert.Equal(expectedFloat, floatVal); @@ -1325,7 +1325,7 @@ namespace System.Text.Json.Tests DateTime expectedDateTime = DateTime.Parse(expectedString); DateTimeOffset expectedDateTimeOffset = DateTimeOffset.Parse(expectedString); - Assert.Equal(JsonValueType.String, root.Type); + Assert.Equal(JsonValueKind.String, root.ValueKind); Assert.True(root.TryGetDateTime(out DateTime DateTimeVal)); Assert.Equal(expectedDateTime, DateTimeVal); @@ -1364,7 +1364,7 @@ namespace System.Text.Json.Tests DateTime expectedDateTime = DateTime.ParseExact(expectedString, "O", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind); DateTimeOffset expectedDateTimeOffset = DateTimeOffset.ParseExact(expectedString, "O", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind); - Assert.Equal(JsonValueType.String, root.Type); + Assert.Equal(JsonValueKind.String, root.ValueKind); Assert.True(root.TryGetDateTime(out DateTime DateTimeVal)); Assert.Equal(expectedDateTime, DateTimeVal); @@ -1387,7 +1387,7 @@ namespace System.Text.Json.Tests { JsonElement root = doc.RootElement; - Assert.Equal(JsonValueType.String, root.Type); + Assert.Equal(JsonValueKind.String, root.ValueKind); Assert.False(root.TryGetDateTime(out DateTime DateTimeVal)); Assert.Equal(default, DateTimeVal); @@ -1412,7 +1412,7 @@ namespace System.Text.Json.Tests Guid expected = new Guid(expectedStr); - Assert.Equal(JsonValueType.String, root.Type); + Assert.Equal(JsonValueKind.String, root.ValueKind); Assert.True(root.TryGetGuid(out Guid GuidVal)); Assert.Equal(expected, GuidVal); @@ -1444,7 +1444,7 @@ namespace System.Text.Json.Tests { JsonElement root = doc.RootElement; - Assert.Equal(JsonValueType.String, root.Type); + Assert.Equal(JsonValueKind.String, root.ValueKind); Assert.False(root.TryGetGuid(out Guid GuidVal)); Assert.Equal(default, GuidVal); @@ -1473,7 +1473,7 @@ namespace System.Text.Json.Tests { JsonElement root = doc.RootElement; - Assert.Equal(JsonValueType.Number, root.Type); + Assert.Equal(JsonValueKind.Number, root.ValueKind); Assert.True(root.TryGetSingle(out float floatVal)); Assert.Equal(expectedFloat, floatVal); @@ -1545,7 +1545,7 @@ namespace System.Text.Json.Tests { JsonElement root = doc.RootElement; - Assert.Equal(JsonValueType.Number, root.Type); + Assert.Equal(JsonValueKind.Number, root.ValueKind); if (PlatformDetection.IsFullFramework) { @@ -1644,7 +1644,7 @@ namespace System.Text.Json.Tests { JsonElement root = doc.RootElement; - Assert.Equal(JsonValueType.Array, root.Type); + Assert.Equal(JsonValueKind.Array, root.ValueKind); Assert.Equal(5, root.GetArrayLength()); for (int i = root.GetArrayLength() - 1; i >= 0; i--) @@ -1701,7 +1701,7 @@ namespace System.Text.Json.Tests JsonElement root = doc.RootElement; doc.Dispose(); - Assert.Throws(() => root.Type); + Assert.Throws(() => root.ValueKind); Assert.Throws(() => root.GetArrayLength()); Assert.Throws(() => root.EnumerateArray()); Assert.Throws(() => root.EnumerateObject()); @@ -1764,7 +1764,7 @@ namespace System.Text.Json.Tests { JsonElement root = default; - Assert.Equal(JsonValueType.Undefined, root.Type); + Assert.Equal(JsonValueKind.Undefined, root.ValueKind); Assert.Throws(() => root.GetArrayLength()); Assert.Throws(() => root.EnumerateArray()); @@ -1848,7 +1848,7 @@ namespace System.Text.Json.Tests JsonElement root = doc.RootElement; const string ErrorMessage = "Cannot transcode invalid UTF-8 JSON text to UTF-16 string."; - Assert.Equal(JsonValueType.String, root.Type); + Assert.Equal(JsonValueKind.String, root.ValueKind); AssertExtensions.Throws(() => root.GetString(), ErrorMessage); Assert.Throws(() => root.GetRawText()); const string DummyString = "dummy-string"; @@ -1868,7 +1868,7 @@ namespace System.Text.Json.Tests { JsonElement root = doc.RootElement; - Assert.Equal(JsonValueType.String, root.Type); + Assert.Equal(JsonValueKind.String, root.ValueKind); Assert.Throws(() => root.GetBytesFromBase64()); Assert.False(root.TryGetBytesFromBase64(out byte[] value)); Assert.Null(value); @@ -2011,19 +2011,19 @@ namespace System.Text.Json.Tests void assertPascal(JsonElement elem) { - Assert.Equal(JsonValueType.String, elem.Type); + Assert.Equal(JsonValueKind.String, elem.ValueKind); Assert.Equal("no", elem.GetString()); } void assertCamel(JsonElement elem) { - Assert.Equal(JsonValueType.Number, elem.Type); + Assert.Equal(JsonValueKind.Number, elem.ValueKind); Assert.Equal(42, elem.GetInt32()); } void assertOdd(JsonElement elem) { - Assert.Equal(JsonValueType.False, elem.Type); + Assert.Equal(JsonValueKind.False, elem.ValueKind); Assert.Equal(false, elem.GetBoolean()); } @@ -2105,18 +2105,18 @@ namespace System.Text.Json.Tests using (JsonDocument doc = JsonDocument.Parse(okayJson)) { JsonElement root = doc.RootElement; - Assert.Equal(JsonValueType.Array, root.Type); + Assert.Equal(JsonValueKind.Array, root.ValueKind); JsonElement cur = root; - while (cur.Type == JsonValueType.Array) + while (cur.ValueKind == JsonValueKind.Array) { Assert.Equal(1, cur.GetArrayLength()); cur = cur[0]; depth++; } - Assert.Equal(JsonValueType.Number, cur.Type); + Assert.Equal(JsonValueKind.Number, cur.ValueKind); Assert.Equal(2, cur.GetInt32()); Assert.Equal(OkayCount, depth); } @@ -2136,18 +2136,18 @@ namespace System.Text.Json.Tests using (JsonDocument doc = JsonDocument.Parse(okayJson, new JsonDocumentOptions { MaxDepth = OkayCount })) { JsonElement root = doc.RootElement; - Assert.Equal(JsonValueType.Array, root.Type); + Assert.Equal(JsonValueKind.Array, root.ValueKind); JsonElement cur = root; - while (cur.Type == JsonValueType.Array) + while (cur.ValueKind == JsonValueKind.Array) { Assert.Equal(1, cur.GetArrayLength()); cur = cur[0]; depth++; } - Assert.Equal(JsonValueType.Number, cur.Type); + Assert.Equal(JsonValueKind.Number, cur.ValueKind); Assert.Equal(2, cur.GetInt32()); Assert.Equal(OkayCount, depth); } @@ -2169,13 +2169,13 @@ namespace System.Text.Json.Tests using (JsonDocument doc = JsonDocument.Parse(okayJson, new JsonDocumentOptions { MaxDepth = MaxDepthOverflow })) { JsonElement root = doc.RootElement; - Assert.Equal(JsonValueType.Array, root.Type); + Assert.Equal(JsonValueKind.Array, root.ValueKind); } using (JsonDocument doc = JsonDocument.Parse(okayJson, new JsonDocumentOptions { MaxDepth = int.MaxValue })) { JsonElement root = doc.RootElement; - Assert.Equal(JsonValueType.Array, root.Type); + Assert.Equal(JsonValueKind.Array, root.ValueKind); } } @@ -2235,7 +2235,7 @@ namespace System.Text.Json.Tests using (JsonDocument doc = JsonDocument.Parse("/* some comment */{ }", options)) { - Assert.Equal(JsonValueType.Object, doc.RootElement.Type); + Assert.Equal(JsonValueKind.Object, doc.RootElement.ValueKind); } } @@ -2630,8 +2630,8 @@ namespace System.Text.Json.Tests JsonElement.ArrayEnumerator enumerator = enumerable.GetEnumerator(); JsonElement.ArrayEnumerator defaultEnumerator = default; - Assert.Equal(JsonValueType.Undefined, enumerable.Current.Type); - Assert.Equal(JsonValueType.Undefined, enumerator.Current.Type); + Assert.Equal(JsonValueKind.Undefined, enumerable.Current.ValueKind); + Assert.Equal(JsonValueKind.Undefined, enumerator.Current.ValueKind); Assert.False(enumerable.MoveNext()); Assert.False(enumerable.MoveNext()); @@ -2808,8 +2808,8 @@ namespace System.Text.Json.Tests JsonElement.ObjectEnumerator enumerator = enumerable.GetEnumerator(); JsonElement.ObjectEnumerator defaultEnumerator = default; - Assert.Equal(JsonValueType.Undefined, enumerable.Current.Value.Type); - Assert.Equal(JsonValueType.Undefined, enumerator.Current.Value.Type); + Assert.Equal(JsonValueKind.Undefined, enumerable.Current.Value.ValueKind); + Assert.Equal(JsonValueKind.Undefined, enumerator.Current.Value.ValueKind); Assert.Throws(() => enumerable.Current.Name); Assert.Throws(() => enumerator.Current.Name); @@ -2842,11 +2842,11 @@ namespace System.Text.Json.Tests using (JsonDocument doc = JsonDocument.Parse(json)) { JsonElement root = doc.RootElement; - Assert.Equal(JsonValueType.Object, root.Type); + Assert.Equal(JsonValueKind.Object, root.ValueKind); Assert.True(root.GetProperty("first").GetProperty("true").GetBoolean()); Assert.False(root.GetProperty("first").GetProperty("false").GetBoolean()); - Assert.Equal(JsonValueType.Null, root.GetProperty("first").GetProperty("null").Type); + Assert.Equal(JsonValueKind.Null, root.GetProperty("first").GetProperty("null").ValueKind); Assert.Equal(3, root.GetProperty("first").GetProperty("int").GetInt32()); Assert.Equal(3.14159f, root.GetProperty("first").GetProperty("nearlyPi").GetSingle()); Assert.Equal("This is some text that does not end... ", root.GetProperty("first").GetProperty("text").GetString()); @@ -3441,7 +3441,7 @@ namespace System.Text.Json.Tests Assert.True(jElement.ValueEquals(default(ReadOnlySpan))); Assert.True(jElement.ValueEquals((ReadOnlySpan)null)); Assert.True(jElement.ValueEquals(default(ReadOnlySpan))); - + Assert.False(jElement.ValueEquals(Array.Empty())); Assert.False(jElement.ValueEquals("")); Assert.False(jElement.ValueEquals("".AsSpan())); diff --git a/src/libraries/System.Text.Json/tests/JsonElementCloneTests.cs b/src/libraries/System.Text.Json/tests/JsonElementCloneTests.cs index 7418317..41db558 100644 --- a/src/libraries/System.Text.Json/tests/JsonElementCloneTests.cs +++ b/src/libraries/System.Text.Json/tests/JsonElementCloneTests.cs @@ -60,31 +60,31 @@ namespace System.Text.Json.Tests [Fact] public static void CloneAtInnerNumber() { - CloneAtInner("1.21e9", JsonValueType.Number); + CloneAtInner("1.21e9", JsonValueKind.Number); } [Fact] public static void CloneAtInnerString() { - CloneAtInner("\" this string has \\u0039 spaces\"", JsonValueType.String); + CloneAtInner("\" this string has \\u0039 spaces\"", JsonValueKind.String); } [Fact] public static void CloneAtInnerTrue() { - CloneAtInner("true", JsonValueType.True); + CloneAtInner("true", JsonValueKind.True); } [Fact] public static void CloneAtInnerFalse() { - CloneAtInner("false", JsonValueType.False); + CloneAtInner("false", JsonValueKind.False); } [Fact] public static void CloneAtInnerNull() { - CloneAtInner("null", JsonValueType.Null); + CloneAtInner("null", JsonValueKind.Null); } [Fact] @@ -106,7 +106,7 @@ namespace System.Text.Json.Tests } ] }", - JsonValueType.Object); + JsonValueKind.Object); } [Fact] @@ -142,10 +142,10 @@ false, null ]", - JsonValueType.Array); + JsonValueKind.Array); } - private static void CloneAtInner(string innerJson, JsonValueType valueType) + private static void CloneAtInner(string innerJson, JsonValueKind valueType) { string json = $"{{ \"obj\": [ {{ \"not target\": true, \"target\": {innerJson} }}, 5 ] }}"; @@ -154,7 +154,7 @@ null using (JsonDocument doc = JsonDocument.Parse(json)) { JsonElement target = doc.RootElement.GetProperty("obj")[0].GetProperty("target"); - Assert.Equal(valueType, target.Type); + Assert.Equal(valueType, target.ValueKind); clone = target.Clone(); } diff --git a/src/libraries/System.Text.Json/tests/Serialization/DictionaryTests.cs b/src/libraries/System.Text.Json/tests/Serialization/DictionaryTests.cs index 421dde3..a4f907d 100644 --- a/src/libraries/System.Text.Json/tests/Serialization/DictionaryTests.cs +++ b/src/libraries/System.Text.Json/tests/Serialization/DictionaryTests.cs @@ -146,7 +146,7 @@ namespace System.Text.Json.Serialization.Tests Dictionary obj = JsonSerializer.Deserialize>(@"{""Key1"":1}"); Assert.Equal(1, obj.Count); JsonElement element = (JsonElement)obj["Key1"]; - Assert.Equal(JsonValueType.Number, element.Type); + Assert.Equal(JsonValueKind.Number, element.ValueKind); Assert.Equal(1, element.GetInt32()); string json = JsonSerializer.Serialize(obj); @@ -157,7 +157,7 @@ namespace System.Text.Json.Serialization.Tests IDictionary obj = JsonSerializer.Deserialize>(@"{""Key1"":1}"); Assert.Equal(1, obj.Count); JsonElement element = (JsonElement)obj["Key1"]; - Assert.Equal(JsonValueType.Number, element.Type); + Assert.Equal(JsonValueKind.Number, element.ValueKind); Assert.Equal(1, element.GetInt32()); string json = JsonSerializer.Serialize(obj); diff --git a/src/libraries/System.Text.Json/tests/Serialization/ExtensionDataTests.cs b/src/libraries/System.Text.Json/tests/Serialization/ExtensionDataTests.cs index 92526ae..06598b4 100644 --- a/src/libraries/System.Text.Json/tests/Serialization/ExtensionDataTests.cs +++ b/src/libraries/System.Text.Json/tests/Serialization/ExtensionDataTests.cs @@ -141,7 +141,7 @@ namespace System.Text.Json.Serialization.Tests // Baseline with missing. ClassWithExtensionProperty obj = JsonSerializer.Deserialize(jsonMissing); Assert.Equal(1, obj.MyOverflow.Count); - Assert.Equal(JsonValueType.Null, obj.MyOverflow["MyNestedClassMissing"].Type); + Assert.Equal(JsonValueKind.Null, obj.MyOverflow["MyNestedClassMissing"].ValueKind); } { @@ -153,7 +153,7 @@ namespace System.Text.Json.Serialization.Tests // Currently we do not ignore nulls in the extension data. The JsonDocument would also need to support this mode // for any lower-level nulls. Assert.Equal(1, obj.MyOverflow.Count); - Assert.Equal(JsonValueType.Null, obj.MyOverflow["MyNestedClassMissing"].Type); + Assert.Equal(JsonValueKind.Null, obj.MyOverflow["MyNestedClassMissing"].ValueKind); } } @@ -217,22 +217,22 @@ namespace System.Text.Json.Serialization.Tests Assert.IsType(roundTripObj.MyOverflow["test2"]); Assert.IsType(roundTripObj.MyOverflow["test3"]); - Assert.Equal(JsonValueType.Object, ((JsonElement)roundTripObj.MyOverflow["test"]).Type); + Assert.Equal(JsonValueKind.Object, ((JsonElement)roundTripObj.MyOverflow["test"]).ValueKind); - Assert.Equal(JsonValueType.Number, ((JsonElement)roundTripObj.MyOverflow["test1"]).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)roundTripObj.MyOverflow["test1"]).ValueKind); Assert.Equal(1, ((JsonElement)roundTripObj.MyOverflow["test1"]).GetInt32()); Assert.Equal(1, ((JsonElement)roundTripObj.MyOverflow["test1"]).GetInt64()); - Assert.Equal(JsonValueType.String, ((JsonElement)roundTripObj.MyOverflow["test2"]).Type); + Assert.Equal(JsonValueKind.String, ((JsonElement)roundTripObj.MyOverflow["test2"]).ValueKind); Assert.Equal("text", ((JsonElement)roundTripObj.MyOverflow["test2"]).GetString()); - Assert.Equal(JsonValueType.Object, ((JsonElement)roundTripObj.MyOverflow["test3"]).Type); + Assert.Equal(JsonValueKind.Object, ((JsonElement)roundTripObj.MyOverflow["test3"]).ValueKind); Assert.Equal("ObjectProp", ((JsonElement)roundTripObj.MyOverflow["test3"]).GetProperty("Prop").GetString()); - Assert.Equal(JsonValueType.Object, ((JsonElement)roundTripObj.MyOverflow["test4"]).Type); + Assert.Equal(JsonValueKind.Object, ((JsonElement)roundTripObj.MyOverflow["test4"]).ValueKind); Assert.Equal("StructProp", ((JsonElement)roundTripObj.MyOverflow["test4"]).GetProperty("Prop").GetString()); - Assert.Equal(JsonValueType.Object, ((JsonElement)roundTripObj.MyOverflow["test5"]).Type); + Assert.Equal(JsonValueKind.Object, ((JsonElement)roundTripObj.MyOverflow["test5"]).ValueKind); Assert.Equal("Value", ((JsonElement)roundTripObj.MyOverflow["test5"]).GetProperty("Key").GetString()); Assert.Equal("Value1", ((JsonElement)roundTripObj.MyOverflow["test5"]).GetProperty("Key1").GetString()); } diff --git a/src/libraries/System.Text.Json/tests/Serialization/JsonElementTests.cs b/src/libraries/System.Text.Json/tests/Serialization/JsonElementTests.cs index ebd0dea..211a77d 100644 --- a/src/libraries/System.Text.Json/tests/Serialization/JsonElementTests.cs +++ b/src/libraries/System.Text.Json/tests/Serialization/JsonElementTests.cs @@ -63,27 +63,27 @@ namespace System.Text.Json.Serialization.Tests public void Verify() { - Assert.Equal(JsonValueType.Number, Number.Type); + Assert.Equal(JsonValueKind.Number, Number.ValueKind); Assert.Equal("1", Number.ToString()); - Assert.Equal(JsonValueType.True, True.Type); + Assert.Equal(JsonValueKind.True, True.ValueKind); Assert.Equal("True", True.ToString()); - Assert.Equal(JsonValueType.False, False.Type); + Assert.Equal(JsonValueKind.False, False.ValueKind); Assert.Equal("False", False.ToString()); - Assert.Equal(JsonValueType.String, String.Type); + Assert.Equal(JsonValueKind.String, String.ValueKind); Assert.Equal("Hello", String.ToString()); - Assert.Equal(JsonValueType.Array, Array.Type); + Assert.Equal(JsonValueKind.Array, Array.ValueKind); JsonElement[] elements = Array.EnumerateArray().ToArray(); - Assert.Equal(JsonValueType.Number, elements[0].Type); + Assert.Equal(JsonValueKind.Number, elements[0].ValueKind); Assert.Equal("2", elements[0].ToString()); - Assert.Equal(JsonValueType.False, elements[1].Type); + Assert.Equal(JsonValueKind.False, elements[1].ValueKind); Assert.Equal("False", elements[1].ToString()); - Assert.Equal(JsonValueType.True, elements[2].Type); + Assert.Equal(JsonValueKind.True, elements[2].ValueKind); Assert.Equal("True", elements[2].ToString()); - Assert.Equal(JsonValueType.String, elements[3].Type); + Assert.Equal(JsonValueKind.String, elements[3].ValueKind); Assert.Equal("Goodbye", elements[3].ToString()); - Assert.Equal(JsonValueType.Object, Object.Type); + Assert.Equal(JsonValueKind.Object, Object.ValueKind); Assert.Equal("{}", Object.ToString()); - //Assert.Equal(JsonValueType.Null, Null.Type); + //Assert.Equal(JsonValueKind.Null, Null.ValueKind); //Assert.Equal("Null", Null.ToString()); } } @@ -136,13 +136,13 @@ namespace System.Text.Json.Serialization.Tests public void Verify() { - Assert.Equal(JsonValueType.Number, Array[0].Type); + Assert.Equal(JsonValueKind.Number, Array[0].ValueKind); Assert.Equal("1", Array[0].ToString()); - Assert.Equal(JsonValueType.True, Array[1].Type); + Assert.Equal(JsonValueKind.True, Array[1].ValueKind); Assert.Equal("True", Array[1].ToString()); - Assert.Equal(JsonValueType.False, Array[2].Type); + Assert.Equal(JsonValueKind.False, Array[2].ValueKind); Assert.Equal("False", Array[2].ToString()); - Assert.Equal(JsonValueType.String, Array[3].Type); + Assert.Equal(JsonValueKind.String, Array[3].ValueKind); Assert.Equal("Hello", Array[3].ToString()); } } diff --git a/src/libraries/System.Text.Json/tests/Serialization/Object.ReadTests.cs b/src/libraries/System.Text.Json/tests/Serialization/Object.ReadTests.cs index 70054c2..5fddf57 100644 --- a/src/libraries/System.Text.Json/tests/Serialization/Object.ReadTests.cs +++ b/src/libraries/System.Text.Json/tests/Serialization/Object.ReadTests.cs @@ -95,7 +95,7 @@ namespace System.Text.Json.Serialization.Tests object[] array = JsonSerializer.Deserialize(@"[[]]"); Assert.Equal(1, array.Length); Assert.IsType(array[0]); - Assert.Equal(JsonValueType.Array, ((JsonElement)array[0]).Type); + Assert.Equal(JsonValueKind.Array, ((JsonElement)array[0]).ValueKind); } [Fact] @@ -104,26 +104,26 @@ namespace System.Text.Json.Serialization.Tests object[] array = JsonSerializer.Deserialize(@"[{}]"); Assert.Equal(1, array.Length); Assert.IsType(array[0]); - Assert.Equal(JsonValueType.Object, ((JsonElement)array[0]).Type); + Assert.Equal(JsonValueKind.Object, ((JsonElement)array[0]).ValueKind); // Scenario described in https://github.com/dotnet/corefx/issues/36169 array = JsonSerializer.Deserialize("[1, false]"); Assert.Equal(2, array.Length); Assert.IsType(array[0]); - Assert.Equal(JsonValueType.Number, ((JsonElement)array[0]).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)array[0]).ValueKind); Assert.Equal(1, ((JsonElement)array[0]).GetInt32()); Assert.IsType(array[1]); - Assert.Equal(JsonValueType.False, ((JsonElement)array[1]).Type); + Assert.Equal(JsonValueKind.False, ((JsonElement)array[1]).ValueKind); array = JsonSerializer.Deserialize(@"[1, false, { ""name"" : ""Person"" }]"); Assert.Equal(3, array.Length); Assert.IsType(array[0]); - Assert.Equal(JsonValueType.Number, ((JsonElement)array[0]).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)array[0]).ValueKind); Assert.Equal(1, ((JsonElement)array[0]).GetInt32()); Assert.IsType(array[1]); - Assert.Equal(JsonValueType.False, ((JsonElement)array[1]).Type); + Assert.Equal(JsonValueKind.False, ((JsonElement)array[1]).ValueKind); Assert.IsType(array[2]); - Assert.Equal(JsonValueType.Object, ((JsonElement)array[2]).Type); + Assert.Equal(JsonValueKind.Object, ((JsonElement)array[2]).ValueKind); } [Fact] diff --git a/src/libraries/System.Text.Json/tests/Serialization/PolymorphicTests.cs b/src/libraries/System.Text.Json/tests/Serialization/PolymorphicTests.cs index 27dc0ad..6ef38d7 100644 --- a/src/libraries/System.Text.Json/tests/Serialization/PolymorphicTests.cs +++ b/src/libraries/System.Text.Json/tests/Serialization/PolymorphicTests.cs @@ -54,12 +54,12 @@ namespace System.Text.Json.Serialization.Tests object obj = JsonSerializer.Deserialize(@"""hello"""); Assert.IsType(obj); JsonElement element = (JsonElement)obj; - Assert.Equal(JsonValueType.String, element.Type); + Assert.Equal(JsonValueKind.String, element.ValueKind); Assert.Equal("hello", element.GetString()); obj = JsonSerializer.Deserialize(@"true"); element = (JsonElement)obj; - Assert.Equal(JsonValueType.True, element.Type); + Assert.Equal(JsonValueKind.True, element.ValueKind); Assert.Equal(true, element.GetBoolean()); obj = JsonSerializer.Deserialize(@"null"); @@ -67,7 +67,7 @@ namespace System.Text.Json.Serialization.Tests obj = JsonSerializer.Deserialize(@"[]"); element = (JsonElement)obj; - Assert.Equal(JsonValueType.Array, element.Type); + Assert.Equal(JsonValueKind.Array, element.ValueKind); } [Fact] diff --git a/src/libraries/System.Text.Json/tests/Serialization/SpanTests.cs b/src/libraries/System.Text.Json/tests/Serialization/SpanTests.cs index c8e6b78..a36c8e6 100644 --- a/src/libraries/System.Text.Json/tests/Serialization/SpanTests.cs +++ b/src/libraries/System.Text.Json/tests/Serialization/SpanTests.cs @@ -62,7 +62,7 @@ namespace System.Text.Json.Serialization.Tests object obj = JsonSerializer.Deserialize(bytes, typeof(object)); Assert.IsType(obj); JsonElement element = (JsonElement)obj; - Assert.Equal(JsonValueType.Number, element.Type); + Assert.Equal(JsonValueKind.Number, element.ValueKind); Assert.Equal(42, element.GetInt32()); } diff --git a/src/libraries/System.Text.Json/tests/Serialization/TestClasses.SimpleTestClassWithObjectArrays.cs b/src/libraries/System.Text.Json/tests/Serialization/TestClasses.SimpleTestClassWithObjectArrays.cs index 36f1936..db599a6 100644 --- a/src/libraries/System.Text.Json/tests/Serialization/TestClasses.SimpleTestClassWithObjectArrays.cs +++ b/src/libraries/System.Text.Json/tests/Serialization/TestClasses.SimpleTestClassWithObjectArrays.cs @@ -90,62 +90,62 @@ namespace System.Text.Json.Serialization.Tests return; Assert.IsType(MyInt16[0]); - Assert.Equal(JsonValueType.Number, ((JsonElement)MyInt16[0]).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)MyInt16[0]).ValueKind); Assert.Equal(1, ((JsonElement)MyInt16[0]).GetInt16()); Assert.IsType(MyInt32[0]); - Assert.Equal(JsonValueType.Number, ((JsonElement)MyInt32[0]).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)MyInt32[0]).ValueKind); Assert.Equal(2, ((JsonElement)MyInt32[0]).GetInt32()); Assert.IsType(MyInt64[0]); - Assert.Equal(JsonValueType.Number, ((JsonElement)MyInt64[0]).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)MyInt64[0]).ValueKind); Assert.Equal(3L, ((JsonElement)MyInt64[0]).GetInt64()); Assert.IsType(MyUInt16[0]); - Assert.Equal(JsonValueType.Number, ((JsonElement)MyUInt16[0]).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)MyUInt16[0]).ValueKind); Assert.Equal(4u, ((JsonElement)MyUInt16[0]).GetUInt16()); Assert.IsType(MyUInt32[0]); - Assert.Equal(JsonValueType.Number, ((JsonElement)MyUInt32[0]).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)MyUInt32[0]).ValueKind); Assert.Equal(5u, ((JsonElement)MyUInt32[0]).GetUInt32()); Assert.IsType(MyUInt64[0]); - Assert.Equal(JsonValueType.Number, ((JsonElement)MyUInt64[0]).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)MyUInt64[0]).ValueKind); Assert.Equal(6UL, ((JsonElement)MyUInt64[0]).GetUInt64()); Assert.IsType(MyByte[0]); - Assert.Equal(JsonValueType.Number, ((JsonElement)MyByte[0]).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)MyByte[0]).ValueKind); Assert.Equal(7, ((JsonElement)MyByte[0]).GetByte()); Assert.IsType(MySByte[0]); - Assert.Equal(JsonValueType.Number, ((JsonElement)MySByte[0]).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)MySByte[0]).ValueKind); Assert.Equal(8, ((JsonElement)MySByte[0]).GetSByte()); Assert.IsType(MyChar[0]); - Assert.Equal(JsonValueType.String, ((JsonElement)MyChar[0]).Type); + Assert.Equal(JsonValueKind.String, ((JsonElement)MyChar[0]).ValueKind); Assert.Equal("a", ((JsonElement)MyChar[0]).GetString()); Assert.IsType(MyString[0]); - Assert.Equal(JsonValueType.String, ((JsonElement)MyString[0]).Type); + Assert.Equal(JsonValueKind.String, ((JsonElement)MyString[0]).ValueKind); Assert.Equal("Hello", ((JsonElement)MyString[0]).GetString()); Assert.IsType(MyDecimal[0]); - Assert.Equal(JsonValueType.Number, ((JsonElement)MyDecimal[0]).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)MyDecimal[0]).ValueKind); Assert.Equal(3.3m, ((JsonElement)MyDecimal[0]).GetDecimal()); Assert.IsType(MyBooleanFalse[0]); - Assert.Equal(JsonValueType.False, ((JsonElement)MyBooleanFalse[0]).Type); + Assert.Equal(JsonValueKind.False, ((JsonElement)MyBooleanFalse[0]).ValueKind); Assert.Equal(false, ((JsonElement)MyBooleanFalse[0]).GetBoolean()); Assert.IsType(MyBooleanTrue[0]); - Assert.Equal(JsonValueType.True, ((JsonElement)MyBooleanTrue[0]).Type); + Assert.Equal(JsonValueKind.True, ((JsonElement)MyBooleanTrue[0]).ValueKind); Assert.Equal(true, ((JsonElement)MyBooleanTrue[0]).GetBoolean()); Assert.IsType(MySingle[0]); - Assert.Equal(JsonValueType.Number, ((JsonElement)MySingle[0]).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)MySingle[0]).ValueKind); Assert.Equal(1.1f, ((JsonElement)MySingle[0]).GetSingle()); Assert.IsType(MyDouble[0]); - Assert.Equal(JsonValueType.Number, ((JsonElement)MyDouble[0]).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)MyDouble[0]).ValueKind); Assert.Equal(2.2d, ((JsonElement)MyDouble[0]).GetDouble()); Assert.IsType(MyDateTime[0]); - Assert.Equal(JsonValueType.String, ((JsonElement)MyDateTime[0]).Type); + Assert.Equal(JsonValueKind.String, ((JsonElement)MyDateTime[0]).ValueKind); Assert.Equal(new DateTime(2019, 1, 30, 12, 1, 2, DateTimeKind.Utc), ((JsonElement)MyDateTime[0]).GetDateTime()); Assert.IsType(MyGuid[0]); - Assert.Equal(JsonValueType.String, ((JsonElement)MyGuid[0]).Type); + Assert.Equal(JsonValueKind.String, ((JsonElement)MyGuid[0]).ValueKind); Assert.Equal(new Guid("97E9F02C-337E-4615-B26C-0020F5DC28C9"), ((JsonElement)MyGuid[0]).GetGuid()); Assert.IsType(MyUri[0]); - Assert.Equal(JsonValueType.String, ((JsonElement)MyUri[0]).Type); + Assert.Equal(JsonValueKind.String, ((JsonElement)MyUri[0]).ValueKind); // TODO: Use JsonElement.GetUri() when https://github.com/dotnet/corefx/issues/38647 is implemented. Assert.Equal(new Uri("https://github.com/dotnet/corefx"), new Uri(((JsonElement)MyUri[0]).GetString())); Assert.IsType(MyEnum[0]); - Assert.Equal(JsonValueType.Number, ((JsonElement)MyEnum[0]).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)MyEnum[0]).ValueKind); Assert.Equal(SampleEnum.Two, (SampleEnum)((JsonElement)MyEnum[0]).GetUInt32()); } } diff --git a/src/libraries/System.Text.Json/tests/Serialization/TestClasses.SimpleTestClassWithSimpleObject.cs b/src/libraries/System.Text.Json/tests/Serialization/TestClasses.SimpleTestClassWithSimpleObject.cs index fba98b0..332cf25 100644 --- a/src/libraries/System.Text.Json/tests/Serialization/TestClasses.SimpleTestClassWithSimpleObject.cs +++ b/src/libraries/System.Text.Json/tests/Serialization/TestClasses.SimpleTestClassWithSimpleObject.cs @@ -89,58 +89,58 @@ namespace System.Text.Json.Serialization.Tests return; Assert.IsType(MyInt16); - Assert.Equal(JsonValueType.Number, ((JsonElement)MyInt16).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)MyInt16).ValueKind); Assert.Equal(1, ((JsonElement)MyInt16).GetInt16()); Assert.IsType(MyInt32); - Assert.Equal(JsonValueType.Number, ((JsonElement)MyInt32).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)MyInt32).ValueKind); Assert.Equal(2, ((JsonElement)MyInt32).GetInt32()); Assert.IsType(MyInt64); - Assert.Equal(JsonValueType.Number, ((JsonElement)MyInt64).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)MyInt64).ValueKind); Assert.Equal(3L, ((JsonElement)MyInt64).GetInt64()); Assert.IsType(MyUInt16); - Assert.Equal(JsonValueType.Number, ((JsonElement)MyUInt16).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)MyUInt16).ValueKind); Assert.Equal(4u, ((JsonElement)MyUInt16).GetUInt16()); Assert.IsType(MyUInt32); - Assert.Equal(JsonValueType.Number, ((JsonElement)MyUInt32).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)MyUInt32).ValueKind); Assert.Equal(5u, ((JsonElement)MyUInt32).GetUInt32()); Assert.IsType(MyUInt64); - Assert.Equal(JsonValueType.Number, ((JsonElement)MyUInt64).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)MyUInt64).ValueKind); Assert.Equal(6UL, ((JsonElement)MyUInt64).GetUInt64()); Assert.IsType(MyByte); - Assert.Equal(JsonValueType.Number, ((JsonElement)MyByte).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)MyByte).ValueKind); Assert.Equal(7, ((JsonElement)MyByte).GetByte()); Assert.IsType(MySByte); - Assert.Equal(JsonValueType.Number, ((JsonElement)MySByte).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)MySByte).ValueKind); Assert.Equal(8, ((JsonElement)MySByte).GetSByte()); Assert.IsType(MyChar); - Assert.Equal(JsonValueType.String, ((JsonElement)MyChar).Type); + Assert.Equal(JsonValueKind.String, ((JsonElement)MyChar).ValueKind); Assert.Equal("a", ((JsonElement)MyChar).GetString()); Assert.IsType(MyString); - Assert.Equal(JsonValueType.String, ((JsonElement)MyString).Type); + Assert.Equal(JsonValueKind.String, ((JsonElement)MyString).ValueKind); Assert.Equal("Hello", ((JsonElement)MyString).GetString()); Assert.IsType(MyDecimal); - Assert.Equal(JsonValueType.Number, ((JsonElement)MyDecimal).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)MyDecimal).ValueKind); Assert.Equal(3.3m, ((JsonElement)MyDecimal).GetDecimal()); Assert.IsType(MyBooleanFalse); - Assert.Equal(JsonValueType.False, ((JsonElement)MyBooleanFalse).Type); + Assert.Equal(JsonValueKind.False, ((JsonElement)MyBooleanFalse).ValueKind); Assert.Equal(false, ((JsonElement)MyBooleanFalse).GetBoolean()); Assert.IsType(MyBooleanTrue); - Assert.Equal(JsonValueType.True, ((JsonElement)MyBooleanTrue).Type); + Assert.Equal(JsonValueKind.True, ((JsonElement)MyBooleanTrue).ValueKind); Assert.Equal(true, ((JsonElement)MyBooleanTrue).GetBoolean()); Assert.IsType(MySingle); - Assert.Equal(JsonValueType.Number, ((JsonElement)MySingle).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)MySingle).ValueKind); Assert.Equal(1.1f, ((JsonElement)MySingle).GetSingle()); Assert.IsType(MyDouble); - Assert.Equal(JsonValueType.Number, ((JsonElement)MyDouble).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)MyDouble).ValueKind); Assert.Equal(2.2d, ((JsonElement)MyDouble).GetDouble()); Assert.IsType(MyDateTime); - Assert.Equal(JsonValueType.String, ((JsonElement)MyDateTime).Type); + Assert.Equal(JsonValueKind.String, ((JsonElement)MyDateTime).ValueKind); Assert.Equal(new DateTime(2019, 1, 30, 12, 1, 2, DateTimeKind.Utc), ((JsonElement)MyDateTime).GetDateTime()); Assert.IsType(MyGuid); - Assert.Equal(JsonValueType.String, ((JsonElement)MyGuid).Type); + Assert.Equal(JsonValueKind.String, ((JsonElement)MyGuid).ValueKind); Assert.Equal(new Guid("5BB9D872-DA8A-471E-AA70-08E19102683D"), ((JsonElement)MyGuid).GetGuid()); Assert.IsType(MyEnum); - Assert.Equal(JsonValueType.Number, ((JsonElement)MyEnum).Type); + Assert.Equal(JsonValueKind.Number, ((JsonElement)MyEnum).ValueKind); Assert.Equal(SampleEnum.Two, (SampleEnum)((JsonElement)MyEnum).GetUInt32()); Assert.Equal(1, ((JsonElement)MyStruct).GetProperty("One").GetInt32()); Assert.Equal(3.14, ((JsonElement)MyStruct).GetProperty("Two").GetDouble()); diff --git a/src/libraries/System.Text.Json/tests/TestClasses.ClassWithComplexObjects.cs b/src/libraries/System.Text.Json/tests/TestClasses.ClassWithComplexObjects.cs index 502905d..89a1db8 100644 --- a/src/libraries/System.Text.Json/tests/TestClasses.ClassWithComplexObjects.cs +++ b/src/libraries/System.Text.Json/tests/TestClasses.ClassWithComplexObjects.cs @@ -50,7 +50,7 @@ namespace System.Text.Json.Serialization.Tests ValidateArray((JsonElement)Array); Assert.IsType(Object); JsonElement jsonObject = (JsonElement)Object; - Assert.Equal(JsonValueType.Object, jsonObject.Type); + Assert.Equal(JsonValueKind.Object, jsonObject.ValueKind); JsonElement.ObjectEnumerator enumerator = jsonObject.EnumerateObject(); JsonProperty property = enumerator.First(); Assert.Equal("NestedArray", property.Name); @@ -59,16 +59,16 @@ namespace System.Text.Json.Serialization.Tests void ValidateArray(JsonElement element) { - Assert.Equal(JsonValueType.Array, element.Type); + Assert.Equal(JsonValueKind.Array, element.ValueKind); JsonElement[] elements = element.EnumerateArray().ToArray(); - Assert.Equal(JsonValueType.Number, elements[0].Type); + Assert.Equal(JsonValueKind.Number, elements[0].ValueKind); Assert.Equal("1", elements[0].ToString()); - Assert.Equal(JsonValueType.String, elements[1].Type); + Assert.Equal(JsonValueKind.String, elements[1].ValueKind); Assert.Equal("Hello", elements[1].ToString()); - Assert.Equal(JsonValueType.True, elements[2].Type); + Assert.Equal(JsonValueKind.True, elements[2].ValueKind); Assert.Equal(true, elements[2].GetBoolean()); - Assert.Equal(JsonValueType.False, elements[3].Type); + Assert.Equal(JsonValueKind.False, elements[3].ValueKind); Assert.Equal(false, elements[3].GetBoolean()); } -- 2.7.4