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