【发布时间】:2022-01-20 16:21:19
【问题描述】:
有没有办法在 JsonInclude 之类的请求模型中为复杂类型指定包含或排除的属性?我认为必须为每个请求编写一个 POCO,并且必须为每个 POCO 上的每个属性添加验证属性将是一场噩梦。
public class RegisterUserRequest
{
//Ignore all other properties including their requirement attributes
[JsonInclude("FirstName,LastName,Username,Password")]
public User user { get; set; }
[Required]
public string PasswordConfirmation { get; set; }
[Required]
public string Email { get; set; }
}
【问题讨论】: