fix: 修复后端 JSON 反序列化与循环引用问题
- Program.cs 添加 JsonStringEnumConverter + CamelCase 策略, 修复枚举值和 decimal 反序列化失败 - CreateHealthRecordRequest 改为 class + init 属性, 修复 decimal? 在位置记录中的 JSON 反序列化异常 - 运动计划 /current 端点改用匿名对象投影, 修复 EF Core 导航属性循环引用导致 JSON 无限递归
This commit is contained in:
@@ -27,6 +27,14 @@ if (File.Exists(envPath))
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// ---- JSON 配置(枚举字符串、camelCase)----
|
||||
builder.Services.ConfigureHttpJsonOptions(options =>
|
||||
{
|
||||
options.SerializerOptions.Converters.Add(new System.Text.Json.Serialization.JsonStringEnumConverter());
|
||||
options.SerializerOptions.PropertyNamingPolicy = System.Text.Json.JsonNamingPolicy.CamelCase;
|
||||
options.SerializerOptions.PropertyNameCaseInsensitive = true;
|
||||
});
|
||||
|
||||
// ---- 数据库 ----
|
||||
builder.Services.AddDbContext<AppDbContext>(options =>
|
||||
options.UseNpgsql(builder.Configuration.GetConnectionString("Default") ?? builder.Configuration["DB_CONNECTION"] ?? "Host=localhost;Database=health_manager;Username=postgres;Password=postgres"));
|
||||
|
||||
Reference in New Issue
Block a user