From 3a10facb3635d36c89621ce785a34a2279165bf1 Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Tue, 14 Jan 2025 17:13:42 +0000 Subject: [PATCH] [Monaco]Fix Json format preview setting (#36867) --- .../Formatters/FilePreviewJsonSerializerContext.cs | 1 - src/common/FilePreviewCommon/Formatters/JsonFormatter.cs | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/common/FilePreviewCommon/Formatters/FilePreviewJsonSerializerContext.cs b/src/common/FilePreviewCommon/Formatters/FilePreviewJsonSerializerContext.cs index c6d5961407..d9f72eefc7 100644 --- a/src/common/FilePreviewCommon/Formatters/FilePreviewJsonSerializerContext.cs +++ b/src/common/FilePreviewCommon/Formatters/FilePreviewJsonSerializerContext.cs @@ -7,7 +7,6 @@ using System.Text.Json.Serialization; namespace Microsoft.PowerToys.FilePreviewCommon.Monaco.Formatters; -[JsonSourceGenerationOptions(WriteIndented = true)] [JsonSerializable(typeof(JsonDocument))] internal sealed partial class FilePreviewJsonSerializerContext : JsonSerializerContext { diff --git a/src/common/FilePreviewCommon/Formatters/JsonFormatter.cs b/src/common/FilePreviewCommon/Formatters/JsonFormatter.cs index 7d969db56d..bc30ec23d5 100644 --- a/src/common/FilePreviewCommon/Formatters/JsonFormatter.cs +++ b/src/common/FilePreviewCommon/Formatters/JsonFormatter.cs @@ -14,9 +14,12 @@ namespace Microsoft.PowerToys.FilePreviewCommon.Monaco.Formatters private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions { + WriteIndented = true, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, }; + private static readonly FilePreviewJsonSerializerContext _filePreviewJsonSerializerContext = new(_serializerOptions); + /// public string Format(string value) { @@ -27,8 +30,7 @@ namespace Microsoft.PowerToys.FilePreviewCommon.Monaco.Formatters using (var jDocument = JsonDocument.Parse(value, new JsonDocumentOptions { CommentHandling = JsonCommentHandling.Skip })) { - FilePreviewJsonSerializerContext context = new(_serializerOptions); - return JsonSerializer.Serialize(jDocument, context.JsonDocument); + return JsonSerializer.Serialize(jDocument, _filePreviewJsonSerializerContext.JsonDocument); } } }