【发布时间】:2022-01-23 03:22:58
【问题描述】:
我正在 .net-core 3.1 中开发 Web API
我目前正在使用 Swashbuckle.AspNetCore.Filters 来展示 JSON 日期格式的特定示例。但是,当我使用这个库时,它并没有取[JsonPropertyName]的值。 我的 JSON 示例当前如下所示:
{
"contractCode": 0,
"registers": 0,
"totalDue1": 0,
"totalDue2": 0,
"buildingExpenses": [
{
"ownersAssociationCode": 0,
"functionalUnitCode": 0,
"period": "string",
"ownerName": "string",
"location": "string",
"ownerEmail": "string",
"dueDate1": "21/12/2021",
"amount1": 0,
"dueDate2": "21/12/2021",
"amount2": 0,
"electronicPaymentCode": "string",
"barcode": "string"
}
]
}
在应用 Swashbuckle 之前,它看起来像这样:
{
"Cliente": 0,
"CantidadRegistros": 0,
"TotalesPrimerVencimiento": 0,
"TotalesSegundoVencimiento": 0,
"Detalle": [
{
"Consorcio": 0,
"UnidadFuncional": 0,
"Periodo": "string",
"Propietario": "string",
"Ubicacion": "string",
"Email": "string",
"FechaPrimerVencimiento": "2022-12-10",
"ImportePrimerVencimiento": 0,
"FechaSegundoVencimiento": "2021-12-20",
"ImporteSegundoVencimiento": 0,
"CodigoDePagoElectronico": "string",
"CodigoDeBarras": "string"
}
]
}
我希望它现在也像这样,保留当前应用的示例日期格式 (dd/MM/yyyy)。
根据我阅读的内容,我必须安装 Swashbuckle.AspNetcore.Newtonsoft 包并将其添加到我的状态中,但这对我不起作用。
services.AddSwaggerGenNewtonsoftSupport();
这是我使用的 Dto,我在其中应用 JsonPropertyName:
public class BuildingExpenseResumeInputDto
{
[JsonPropertyName("Cliente")]
public int ContractCode { get; set; }
[JsonPropertyName("CantidadRegistros")]
public int Registers { get; set; }
[JsonPropertyName("TotalesPrimerVencimiento")]
public decimal TotalDue1 { get; set; }
[JsonPropertyName("TotalesSegundoVencimiento")]
public decimal TotalDue2 { get; set; }
[JsonPropertyName("Detalle")]
public List<BuildingExpenseDetailInputDto> BuildingExpenses { get; set; }
public BuildingExpenseResumeInputDto()
{
BuildingExpenses = new List<BuildingExpenseDetailInputDto>();
}
}
希望你能帮我解决!
【问题讨论】:
标签: c# asp.net-core swashbuckle