我正在尝试通过在客户端获取对象时使用 Json Ignore 属性来使 Json .NET Ignore 属性,但我希望能够在客户端发布时接收该属性
例如,我有:
当客户端 POST 数据时,应发送密码:
{"email":"email@domain.com","password":"P@ssW0rd1!","firstname":"Joe","lastname":"Doe"}
但是,当客户端获取相同的对象时,我应该忽略密码:
{"email":"email@domain.com","firstname":"Joe","lastname":"Doe"}
班级:
public class User
{
public User()
{
this.JoinDate = DateTime.UtcNow;
this.IsActive = false;
}
public int Id { get; set; }
[Required(ErrorMessage = "Email is required!")]
public string Email { get; set; }
[JsonIgnore]
public string HashedPassword { get; set; }
[Required(ErrorMessage = "Password is required!")]
public string Password { get; set; }
public DateTime JoinDate { get; set; }
[Required(ErrorMessage = "First Name is required!")]
public string FirstName { get; set; }
[Required(ErrorMessage = "Last Name is required!")]
public string LastName { get; set; }
}
任何想法,建议,意见???