From f59bbb3cacb94171934d8ba7864f98990d871437 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Thu, 2 Apr 2026 13:52:07 -0500 Subject: [PATCH] fix: use internal json context --- .../Storage/JsonFileStorageProvider.cs | 10 +++------- .../Storage/SecureConfigJsonContext.cs | 6 ++++++ 2 files changed, 9 insertions(+), 7 deletions(-) create mode 100644 src/StevanFreeborn.Extensions.Configuration.Secure/Storage/SecureConfigJsonContext.cs diff --git a/src/StevanFreeborn.Extensions.Configuration.Secure/Storage/JsonFileStorageProvider.cs b/src/StevanFreeborn.Extensions.Configuration.Secure/Storage/JsonFileStorageProvider.cs index 19add1f..309abb2 100644 --- a/src/StevanFreeborn.Extensions.Configuration.Secure/Storage/JsonFileStorageProvider.cs +++ b/src/StevanFreeborn.Extensions.Configuration.Secure/Storage/JsonFileStorageProvider.cs @@ -9,10 +9,6 @@ namespace StevanFreeborn.Extensions.Configuration.Secure.Storage; public sealed class JsonFileStorageProvider(JsonStorageOptions options) : ISecureStorageProvider { private static readonly SemaphoreSlim FileLock = new(1, 1); - private static readonly JsonSerializerOptions JsonOptions = new() - { - WriteIndented = true, - }; private readonly JsonStorageOptions _options = options ?? throw new ArgumentNullException(nameof(options)); @@ -128,7 +124,7 @@ public sealed class JsonFileStorageProvider(JsonStorageOptions options) : ISecur return []; } - var data = await JsonSerializer.DeserializeAsync>(stream, cancellationToken: ct) + var data = await JsonSerializer.DeserializeAsync(stream, SecureConfigJsonContext.Default.DictionaryStringString, ct) .ConfigureAwait(false); return data ?? []; @@ -151,7 +147,7 @@ public sealed class JsonFileStorageProvider(JsonStorageOptions options) : ISecur FileShare.None ); - await JsonSerializer.SerializeAsync(stream, data, JsonOptions, ct) + await JsonSerializer.SerializeAsync(stream, data, SecureConfigJsonContext.Default.DictionaryStringString, ct) .ConfigureAwait(false); } -} \ No newline at end of file +} diff --git a/src/StevanFreeborn.Extensions.Configuration.Secure/Storage/SecureConfigJsonContext.cs b/src/StevanFreeborn.Extensions.Configuration.Secure/Storage/SecureConfigJsonContext.cs new file mode 100644 index 0000000..25ff2be --- /dev/null +++ b/src/StevanFreeborn.Extensions.Configuration.Secure/Storage/SecureConfigJsonContext.cs @@ -0,0 +1,6 @@ +using System.Text.Json.Serialization; + +namespace StevanFreeborn.Extensions.Configuration.Secure.Storage; + +[JsonSerializable(typeof(Dictionary))] +internal sealed partial class SecureConfigJsonContext : JsonSerializerContext; \ No newline at end of file