diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.Date.cs b/src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.Date.cs index af0d996a5ec1f2..15da840b29a3e5 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.Date.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.Date.cs @@ -421,8 +421,7 @@ private static bool TryParseDateTimeOffset(ReadOnlySpan source, out DateTi case JsonConstants.Plus: case JsonConstants.Hyphen: parseData.OffsetToken = curByte; - return ParseOffset(ref parseData, source.Slice(sourceIndex)) - && true; + return ParseOffset(ref parseData, source.Slice(sourceIndex)); default: return false; } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/KeyValuePairConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/KeyValuePairConverter.cs index a9e386e74ea83f..fc5035deeb78ef 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/KeyValuePairConverter.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/KeyValuePairConverter.cs @@ -11,11 +11,13 @@ internal sealed class KeyValuePairConverter : JsonValueConverter ReadAsync( var readerState = new JsonReaderState(options.GetReaderOptions()); - // todo: switch to ArrayBuffer implementation to handle and simplify the allocs? + // todo: https://github.com/dotnet/runtime/issues/32355 int utf8BomLength = JsonConstants.Utf8Bom.Length; byte[] buffer = ArrayPool.Shared.Rent(Math.Max(options.DefaultBufferSize, utf8BomLength)); int bytesInBuffer = 0; diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Stream.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Stream.cs index fb42a2b2591c2e..917e092ecbd290 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Stream.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Stream.cs @@ -77,7 +77,9 @@ private static async Task WriteAsyncCore(Stream utf8Json, object? value, Type in do { - state.FlushThreshold = (int)(bufferWriter.Capacity * .9); //todo: determine best value here + // todo: determine best value here + // https://github.com/dotnet/runtime/issues/32356 + state.FlushThreshold = (int)(bufferWriter.Capacity * .9); isFinalBlock = WriteCore( writer, value, diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs index 9497f30bb98031..512d40fefb9d53 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs @@ -334,6 +334,7 @@ internal JsonClassInfo GetOrAddClass(Type classType) _haveTypesBeenCreated = true; // todo: for performance and reduced instances, consider using the converters and JsonClassInfo from s_defaultOptions by cloning (or reference directly if no changes). + // https://github.com/dotnet/runtime/issues/32357 if (!_classes.TryGetValue(classType, out JsonClassInfo? result)) { result = _classes.GetOrAdd(classType, new JsonClassInfo(classType, this)); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/WriteStackFrame.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/WriteStackFrame.cs index 01292e9815cfd5..7261392b71655d 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/WriteStackFrame.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/WriteStackFrame.cs @@ -99,6 +99,7 @@ public JsonConverter InitializeReEntry(Type type, JsonSerializerOptions options, JsonClassInfo newClassInfo = options.GetOrAddClass(type); // todo: check if type==newtype and skip below? + // https://github.com/dotnet/runtime/issues/32358 // Set for exception handling calculation of JsonPath. JsonPropertyNameAsString = propertyName; diff --git a/src/libraries/System.Text.Json/tests/JsonTestHelper.cs b/src/libraries/System.Text.Json/tests/JsonTestHelper.cs index 5af9d786ddc712..06ab14adf457aa 100644 --- a/src/libraries/System.Text.Json/tests/JsonTestHelper.cs +++ b/src/libraries/System.Text.Json/tests/JsonTestHelper.cs @@ -719,7 +719,7 @@ public static void AssertContents(string expectedValue, ArrayBufferWriter ); // Temporary hack until we can use the same escape algorithm on both sides and make sure we want uppercase hex. - // Todo: create new AssertContentsAgainJsonNet to avoid calling NormalizeToJsonNetFormat when not necessary. + // Todo: https://github.com/dotnet/runtime/issues/32351 Assert.Equal(expectedValue.NormalizeToJsonNetFormat(), value.NormalizeToJsonNetFormat()); } @@ -741,7 +741,7 @@ public static void AssertContentsNotEqual(string expectedValue, ArrayBufferWrite ); // Temporary hack until we can use the same escape algorithm on both sides and make sure we want uppercase hex. - // Todo: create new AssertContentsNotEqualAgainJsonNet to avoid calling NormalizeToJsonNetFormat when not necessary. + // Todo: https://github.com/dotnet/runtime/issues/32351 Assert.NotEqual(expectedValue.NormalizeToJsonNetFormat(), value.NormalizeToJsonNetFormat()); } diff --git a/src/libraries/System.Text.Json/tests/Serialization/Array.ReadTests.cs b/src/libraries/System.Text.Json/tests/Serialization/Array.ReadTests.cs index 45b4d2c5ecbaca..8acb14647508e4 100644 --- a/src/libraries/System.Text.Json/tests/Serialization/Array.ReadTests.cs +++ b/src/libraries/System.Text.Json/tests/Serialization/Array.ReadTests.cs @@ -617,7 +617,7 @@ static void TestRoundTrip(ClassWithNonNullEnumerableGetters obj) Assert.Equal(0, obj.MyImmutableList.Count); TestRoundTrip(obj); - // Skip ImmutableArray due to https://github.com/dotnet/corefx/issues/42399. + // TODO: Skip ImmutableArray due to https://github.com/dotnet/runtime/issues/1037. const string inputJsonWithNullCollections = @"{ ""Array"":null, diff --git a/src/libraries/System.Text.Json/tests/Serialization/CustomConverterTests.Callback.cs b/src/libraries/System.Text.Json/tests/Serialization/CustomConverterTests.Callback.cs index aa158a1564773a..d0f00a3c7ee306 100644 --- a/src/libraries/System.Text.Json/tests/Serialization/CustomConverterTests.Callback.cs +++ b/src/libraries/System.Text.Json/tests/Serialization/CustomConverterTests.Callback.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Diagnostics; using Xunit; namespace System.Text.Json.Serialization.Tests @@ -23,14 +24,22 @@ public override Customer Read(ref Utf8JsonReader reader, Type typeToConvert, Jso // The options are not passed here as that would cause an infinite loop. Customer value = JsonSerializer.Deserialize(ref reader); - value.Name = value.Name + "Hello!"; + value.Name += "Hello!"; return value; } public override void Write(Utf8JsonWriter writer, Customer value, JsonSerializerOptions options) { - // todo: there is no WriteValue yet. - throw new NotSupportedException(); + writer.WriteStartArray(); + + long bytesWrittenSoFar = writer.BytesCommitted + writer.BytesPending; + + JsonSerializer.Serialize(writer, value); + + Debug.Assert(writer.BytesPending == 0); + long payloadLength = writer.BytesCommitted - bytesWrittenSoFar; + writer.WriteNumberValue(payloadLength); + writer.WriteEndArray(); } } @@ -44,6 +53,10 @@ public static void ConverterWithCallback() Customer customer = JsonSerializer.Deserialize(json, options); Assert.Equal("MyNameHello!", customer.Name); + + string result = JsonSerializer.Serialize(customer, options); + int expectedLength = JsonSerializer.Serialize(customer).Length; + Assert.Equal(@"[{""CreditLimit"":0,""Name"":""MyNameHello!"",""Address"":{""City"":null}}," + $"{expectedLength}]", result); } } } diff --git a/src/libraries/System.Text.Json/tests/Serialization/DictionaryTests.cs b/src/libraries/System.Text.Json/tests/Serialization/DictionaryTests.cs index 53976926d163ff..6868ffdf9d2081 100644 --- a/src/libraries/System.Text.Json/tests/Serialization/DictionaryTests.cs +++ b/src/libraries/System.Text.Json/tests/Serialization/DictionaryTests.cs @@ -1263,11 +1263,14 @@ public static void ObjectToStringFail() Assert.Throws(() => JsonSerializer.Deserialize>(json)); } - [Fact, ActiveIssue("JsonElement fails since it is a struct.")] + [Fact] public static void ObjectToJsonElement() { string json = @"{""MyDictionary"":{""Key"":""Value""}}"; - JsonSerializer.Deserialize>(json); + Dictionary result = JsonSerializer.Deserialize>(json); + JsonElement element = result["MyDictionary"]; + Assert.Equal(JsonValueKind.Object, element.ValueKind); + Assert.Equal("Value", element.GetProperty("Key").GetString()); } [Fact] diff --git a/src/libraries/System.Text.Json/tests/Serialization/ExceptionTests.cs b/src/libraries/System.Text.Json/tests/Serialization/ExceptionTests.cs index d374f7c3eff20f..32a11928687eb6 100644 --- a/src/libraries/System.Text.Json/tests/Serialization/ExceptionTests.cs +++ b/src/libraries/System.Text.Json/tests/Serialization/ExceptionTests.cs @@ -364,7 +364,7 @@ public static void EscapingFails() } [Fact] - [ActiveIssue("JsonElement needs to support Path")] + [ActiveIssue("https://github.com/dotnet/runtime/issues/32359")] public static void ExtensionPropertyRoundTripFails() { try diff --git a/src/libraries/System.Text.Json/tests/Serialization/Object.WriteTests.cs b/src/libraries/System.Text.Json/tests/Serialization/Object.WriteTests.cs index a8f1a65ed4c08d..34f96ccde1f033 100644 --- a/src/libraries/System.Text.Json/tests/Serialization/Object.WriteTests.cs +++ b/src/libraries/System.Text.Json/tests/Serialization/Object.WriteTests.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Collections.Generic; +using System.Text.Encodings.Web; using Xunit; namespace System.Text.Json.Serialization.Tests @@ -125,5 +126,17 @@ private class Polymorphic [JsonPropertyName("p_3")] public object P3 => ""; } + + // https://github.com/dotnet/corefx/issues/40979 + [Fact] + public static void EscapingShouldntStackOverflow_40979() + { + var test = new { Name = "\u6D4B\u8A6611" }; + + var options = new JsonSerializerOptions { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; + string result = JsonSerializer.Serialize(test, options); + + Assert.Equal("{\"name\":\"\u6D4B\u8A6611\"}", result); + } } } diff --git a/src/libraries/System.Text.Json/tests/Serialization/PropertyVisibilityTests.cs b/src/libraries/System.Text.Json/tests/Serialization/PropertyVisibilityTests.cs index 1fe8fcbb152f99..7686582885247d 100644 --- a/src/libraries/System.Text.Json/tests/Serialization/PropertyVisibilityTests.cs +++ b/src/libraries/System.Text.Json/tests/Serialization/PropertyVisibilityTests.cs @@ -271,7 +271,7 @@ public class WrapperForClassWithIgnoredUnsupportedBigInteger public ClassWithIgnoredUnsupportedBigInteger MyClass { get; set; } } - // Todo: add tests with missing object property and missing collection property. + // Todo: https://github.com/dotnet/runtime/issues/32348 public class ClassWithPrivateSetterAndGetter { diff --git a/src/libraries/System.Text.Json/tests/Serialization/Value.WriteTests.cs b/src/libraries/System.Text.Json/tests/Serialization/Value.WriteTests.cs index f2a0ba67e8454a..6cb8de00d56280 100644 --- a/src/libraries/System.Text.Json/tests/Serialization/Value.WriteTests.cs +++ b/src/libraries/System.Text.Json/tests/Serialization/Value.WriteTests.cs @@ -22,19 +22,6 @@ public static void WriteStringWithRelaxedEscaper() Assert.NotEqual(expected, JsonSerializer.Serialize(inputString)); } - // todo: move this to object tests; it is not a value test. - // https://github.com/dotnet/corefx/issues/40979 - [Fact] - public static void EscapingShouldntStackOverflow_40979() - { - var test = new { Name = "\u6D4B\u8A6611" }; - - var options = new JsonSerializerOptions { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; - string result = JsonSerializer.Serialize(test, options); - - Assert.Equal("{\"name\":\"\u6D4B\u8A6611\"}", result); - } - [Fact] public static void WritePrimitives() { diff --git a/src/libraries/System.Text.Json/tests/Utf8JsonWriterTests.cs b/src/libraries/System.Text.Json/tests/Utf8JsonWriterTests.cs index d24cb8e79193a1..96a05b65dca8c4 100644 --- a/src/libraries/System.Text.Json/tests/Utf8JsonWriterTests.cs +++ b/src/libraries/System.Text.Json/tests/Utf8JsonWriterTests.cs @@ -5554,7 +5554,7 @@ public void WriteNumbers(bool formatted, bool skipValidation, string keyString) jsonUtf8.WriteEndObject(); jsonUtf8.Flush(); - // TODO: The output doesn't match what JSON.NET does (different rounding/e-notation). + // TODO: https://github.com/dotnet/runtime/issues/32350 // JsonTestHelper.AssertContents(expectedStr, output); } }