fix: use internal json context
This commit is contained in:
+3
-7
@@ -9,10 +9,6 @@ namespace StevanFreeborn.Extensions.Configuration.Secure.Storage;
|
|||||||
public sealed class JsonFileStorageProvider(JsonStorageOptions options) : ISecureStorageProvider
|
public sealed class JsonFileStorageProvider(JsonStorageOptions options) : ISecureStorageProvider
|
||||||
{
|
{
|
||||||
private static readonly SemaphoreSlim FileLock = new(1, 1);
|
private static readonly SemaphoreSlim FileLock = new(1, 1);
|
||||||
private static readonly JsonSerializerOptions JsonOptions = new()
|
|
||||||
{
|
|
||||||
WriteIndented = true,
|
|
||||||
};
|
|
||||||
private readonly JsonStorageOptions _options = options
|
private readonly JsonStorageOptions _options = options
|
||||||
?? throw new ArgumentNullException(nameof(options));
|
?? throw new ArgumentNullException(nameof(options));
|
||||||
|
|
||||||
@@ -128,7 +124,7 @@ public sealed class JsonFileStorageProvider(JsonStorageOptions options) : ISecur
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = await JsonSerializer.DeserializeAsync<Dictionary<string, string>>(stream, cancellationToken: ct)
|
var data = await JsonSerializer.DeserializeAsync(stream, SecureConfigJsonContext.Default.DictionaryStringString, ct)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
return data ?? [];
|
return data ?? [];
|
||||||
@@ -151,7 +147,7 @@ public sealed class JsonFileStorageProvider(JsonStorageOptions options) : ISecur
|
|||||||
FileShare.None
|
FileShare.None
|
||||||
);
|
);
|
||||||
|
|
||||||
await JsonSerializer.SerializeAsync(stream, data, JsonOptions, ct)
|
await JsonSerializer.SerializeAsync(stream, data, SecureConfigJsonContext.Default.DictionaryStringString, ct)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace StevanFreeborn.Extensions.Configuration.Secure.Storage;
|
||||||
|
|
||||||
|
[JsonSerializable(typeof(Dictionary<string, string>))]
|
||||||
|
internal sealed partial class SecureConfigJsonContext : JsonSerializerContext;
|
||||||
Reference in New Issue
Block a user