Files
SVSimServer/SVSim.EmulatedEntrypoint/Infrastructure/JsonbReadOptions.cs
2026-05-23 19:57:34 -04:00

27 lines
1.1 KiB
C#

using System.Text.Json;
using System.Text.Json.Serialization;
namespace SVSim.EmulatedEntrypoint.Infrastructure;
/// <summary>
/// Shared System.Text.Json options for deserializing jsonb-passthrough columns into typed DTOs.
///
/// The prod-captured globals JSON was seeded with snake_case_lower keys (see SVSim.Bootstrap
/// GlobalsImporter — jsonb columns store the original capture verbatim). Deserialize-back must
/// use the same naming policy so e.g. `card_pool_name` maps onto `CardPoolName`.
///
/// AllowReadingFromString handles prod's PHP-backend convention of emitting numeric values
/// as JSON strings (e.g. `"ability_id": "1"`). Numeric-typed DTO properties accept those.
///
/// Used by LoadController and MyPageController (and any other controller that reads jsonb).
/// </summary>
public static class JsonbReadOptions
{
public static readonly JsonSerializerOptions Instance = new()
{
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
PropertyNameCaseInsensitive = false,
NumberHandling = JsonNumberHandling.AllowReadingFromString,
};
}