JsonSerializerOptions options,
ref WriteStack state)
{
- bool continueWriting = true;
bool finishedSerializing;
do
{
break;
}
- if (flushThreshold >= 0 && writer.BytesPending > flushThreshold)
+ if (finishedSerializing && writer.CurrentDepth == 0)
{
- return false;
+ break;
}
- if (finishedSerializing && writer.CurrentDepth == 0)
+ // If serialization is not yet end and we surpass beyond flush threshold return false and flush stream.
+ if (flushThreshold >= 0 && writer.BytesPending > flushThreshold)
{
- continueWriting = false;
+ return false;
}
- } while (continueWriting);
+ } while (true);
return true;
}
// See the LICENSE file in the project root for more information.
using System.IO;
-using System.Threading;
using System.Threading.Tasks;
using Xunit;
}
}
+ [Fact]
+ public static async Task RoundTripLargeJsonViaJsonElementAsync()
+ {
+ // Generating tailored json
+ int i = 0;
+ StringBuilder json = new StringBuilder();
+ json.Append("{");
+ while (true)
+ {
+ if (json.Length >= 14757)
+ {
+ break;
+ }
+ json.AppendFormat(@"""Key_{0}"":""{0}"",", i);
+ i++;
+ }
+ json.Remove(json.Length - 1, 1).Append("}");
+
+ JsonElement root = JsonSerializer.Parse<JsonElement>(json.ToString());
+ var ms = new MemoryStream();
+ await JsonSerializer.WriteAsync(ms, root, root.GetType());
+ }
+
+ [Fact]
+ public static async Task RoundTripLargeJsonViaPocoAsync()
+ {
+ byte[] array = JsonSerializer.Parse<byte[]>(JsonSerializer.ToString(new byte[11056]));
+ var ms = new MemoryStream();
+ await JsonSerializer.WriteAsync(ms, array, array.GetType());
+ }
+
private static async Task WriteAsync(TestStream stream)
{
JsonSerializerOptions options = new JsonSerializerOptions