aboutsummaryrefslogtreecommitdiff
path: root/docker/crupest-api/CrupestApi/CrupestApi.Commons/Json.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-12-02 13:23:40 +0800
committercrupest <crupest@outlook.com>2022-12-02 13:35:35 +0800
commitcf85a3edda5953581dd1226fb0c7a1923a405da6 (patch)
tree59f4e3942cc35664993f8bb8b9e4f7bf2ff4f3a3 /docker/crupest-api/CrupestApi/CrupestApi.Commons/Json.cs
parent879fb614c6853ab3bb83155c82722afb2933fc60 (diff)
downloadcrupest-cf85a3edda5953581dd1226fb0c7a1923a405da6.tar.gz
crupest-cf85a3edda5953581dd1226fb0c7a1923a405da6.tar.bz2
crupest-cf85a3edda5953581dd1226fb0c7a1923a405da6.zip
Fix crupest-api bug.
Diffstat (limited to 'docker/crupest-api/CrupestApi/CrupestApi.Commons/Json.cs')
-rw-r--r--docker/crupest-api/CrupestApi/CrupestApi.Commons/Json.cs7
1 files changed, 3 insertions, 4 deletions
diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Json.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Json.cs
index 0ec3ff0..8409a96 100644
--- a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Json.cs
+++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Json.cs
@@ -1,9 +1,8 @@
-using System.Text;
using System.Text.Json;
+using Microsoft.Extensions.Options;
namespace CrupestApi.Commons;
-
public static class CrupestApiJsonExtensions
{
public static IServiceCollection AddJsonOptions(this IServiceCollection services)
@@ -22,8 +21,8 @@ public static class CrupestApiJsonExtensions
public static async Task WriteJsonAsync<T>(this HttpResponse response, T bodyObject, int statusCode = 200, HttpResponseAction? beforeWriteBody = null, CancellationToken cancellationToken = default)
{
- var jsonOptions = response.HttpContext.RequestServices.GetRequiredService<JsonSerializerOptions>();
- byte[] json = JsonSerializer.SerializeToUtf8Bytes<T>(bodyObject, jsonOptions);
+ var jsonOptions = response.HttpContext.RequestServices.GetRequiredService<IOptionsSnapshot<JsonSerializerOptions>>();
+ byte[] json = JsonSerializer.SerializeToUtf8Bytes<T>(bodyObject, jsonOptions.Value);
var byteCount = json.Length;
response.StatusCode = statusCode;