net core 5,由于某種原因,我停止使用 System.text.Json,我使用 NewtonSoft,并將所有命名空間更改為 JsonIgnore,但我的問題是我忽略的屬性仍然顯示在 swagger 輸出中。
using System;
using Newtonsoft.Json;
public class AddEmployeeDto
{
public Guid Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
[JsonIgnore]
public int EmployeeType { get; set; }
}
這是大搖大擺的輸出:
在此處輸入影像描述
uj5u.com熱心網友回復:
既然Sytem.text.Json已經成為 的默認Serialize工具Asp.Net Core,標準版的Swagger也兼容它,并且要改變它,就像你可能已經應用的這個改變,
services.AddControllers().AddNewtonsoftJson();
您必須從以下位置安裝軟體包Nuget:
Swashbuckle.AspNetCore.Newtonsoft
并將其注冊到您的服務容器中,如下所示以解決您的問題
services.AddSwaggerGenNewtonsoftSupport();
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/516909.html
上一篇:如何更改img標簽內的svg顏色
下一篇:如何將輸入元素設定為禁用
