diff --git a/src/mono/sample/wasm/browser-bench/Program.cs b/src/mono/sample/wasm/browser-bench/Program.cs index 2d4278f075d6e..6c3f6d4a207e8 100644 --- a/src/mono/sample/wasm/browser-bench/Program.cs +++ b/src/mono/sample/wasm/browser-bench/Program.cs @@ -7,6 +7,7 @@ using System.IO; using System.Text; using System.Text.Json; +using System.Text.Json.Serialization; using System.Text.RegularExpressions; using System.Runtime.CompilerServices; using System.Threading.Tasks; @@ -209,11 +210,14 @@ class JsonResultsData public DateTime timeStamp; } + [JsonSourceGenerationOptions(IncludeFields = true, WriteIndented = true)] + [JsonSerializable(typeof(JsonResultsData))] + partial class ResultsSerializerContext : JsonSerializerContext { } + string GetJsonResults() { - var options = new JsonSerializerOptions { IncludeFields = true, WriteIndented = true }; var jsonObject = new JsonResultsData { results = results, minTimes = minTimes, timeStamp = DateTime.UtcNow }; - return JsonSerializer.Serialize(jsonObject, options); + return JsonSerializer.Serialize(jsonObject, ResultsSerializerContext.Default.JsonResultsData); } private void PrintJsonResults()