From 4016b3fc19a61a545b9adef3bdf340f57842ae46 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 12 May 2025 21:44:47 -0400 Subject: [PATCH] Serialize JSON a slightly different way --- CHANGELIST.md | 1 + MPF.Frontend/DumpEnvironment.cs | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELIST.md b/CHANGELIST.md index 0fc7df18..b355c3f5 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -49,6 +49,7 @@ - One more note about hidden settings - Explicitly unset Redumper speed, if needed - Simplify WriteOutputData path handling +- Serialize JSON a slightly different way ### 3.3.0 (2025-01-03) diff --git a/MPF.Frontend/DumpEnvironment.cs b/MPF.Frontend/DumpEnvironment.cs index c3f8f2dd..5d65c12b 100644 --- a/MPF.Frontend/DumpEnvironment.cs +++ b/MPF.Frontend/DumpEnvironment.cs @@ -743,10 +743,6 @@ namespace MPF.Frontend try { - // Serialize the JSON and get it writable - string json = JsonConvert.SerializeObject(info, Formatting.Indented); - byte[] jsonBytes = Encoding.UTF8.GetBytes(json); - // Get the output path var path = string.Empty; if (string.IsNullOrEmpty(outputDirectory) && string.IsNullOrEmpty(filenameSuffix)) @@ -765,15 +761,20 @@ namespace MPF.Frontend // Create and open the output file using var fs = File.Create(path); + // Create the JSON serializer + var serializer = new JsonSerializer { Formatting = Formatting.Indented }; + // If we included artifacts, write to a GZip-compressed file if (includedArtifacts) { using var gs = new GZipStream(fs, CompressionMode.Compress); - gs.Write(jsonBytes, 0, jsonBytes.Length); + using var sw = new StreamWriter(gs, Encoding.UTF8); + serializer.Serialize(sw, info); } else { - fs.Write(jsonBytes, 0, jsonBytes.Length); + using var sw = new StreamWriter(fs, Encoding.UTF8); + serializer.Serialize(sw, info); } } catch