🐛 Fixes embedding json loop

This commit is contained in:
2025-08-06 18:07:46 +08:00
parent 4f2e18ca27
commit e85af628bf
2 changed files with 15 additions and 2 deletions

View File

@@ -14,6 +14,13 @@ namespace DysonNetwork.Shared.Proto;
public abstract class GrpcTypeHelper
{
public static readonly JsonSerializerOptions? SerializerOptionsWithIgnore = new JsonSerializerOptions()
{
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
DefaultIgnoreCondition = JsonIgnoreCondition.Never,
PropertyNameCaseInsensitive = true,
}.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
public static readonly JsonSerializerOptions? SerializerOptions = new JsonSerializerOptions()
{
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,

View File

@@ -31,7 +31,13 @@ public abstract class EmbeddableBase
public static Dictionary<string, object> ToDictionary(dynamic input)
{
var jsonRaw = JsonSerializer.Serialize(input, GrpcTypeHelper.SerializerOptions);
return JsonSerializer.Deserialize<Dictionary<string, object>>(jsonRaw, GrpcTypeHelper.SerializerOptions);
var jsonRaw = JsonSerializer.Serialize(
input,
GrpcTypeHelper.SerializerOptionsWithIgnore
);
return JsonSerializer.Deserialize<Dictionary<string, object>>(
jsonRaw,
GrpcTypeHelper.SerializerOptionsWithIgnore
);
}
}