asp.net core web api에서 json 특정 property 무시하는 방법 문의 드립니다. System.Text.Json 사용중입니다.
rest api서버 입니다.
post나 put으로 createdate가 들어와도 무시하고 싶습니다.
controler 에서 _context.Entry(userItem).Property(x => x.createdate).IsModified = false;
하면 되지만
어노테이션이나
설정에서 제외하면 더 좋을것 같아서요.
builder.Services.AddControllers().AddJsonOptions(options =>
{
options.JsonSerializerOptions.IgnoreReadOnlyFields = true;
options.JsonSerializerOptions.IgnoreNullValues = true;
});
미리 답변감사합니다.
put으로 수정한 결과를 뿌려주고 싶은데
지금은 들어온 값을 검증하고 수정 후 성공하면 들어온 값을 그대로 보내고 있습니다.
더 좋은 방법이 있을것 같아서 고민중입니다.
[최초 등록일: ]
[최종 수정일: 11/25/2022]