迁移到.Net Core 3后,JsonPatchDocument为null [英] JsonPatchDocument is null after migration to .Net Core 3
本文介绍了迁移到.Net Core 3后,JsonPatchDocument为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有几个补丁操作的AspNetCore-WebApi-Project,在Core 2.2上运行良好.迁移到Core 3后,[FromBody] JsonPatchDocument<T>
为空.我的Get/Post-Methods仍按预期运行.
I have a AspNetCore-WebApi-Project with several patch-operations, which worked fine with Core 2.2. After migration to Core 3 the [FromBody] JsonPatchDocument<T>
is null. My Get/Post-Methods are still functioning as expected.
这是我的创业公司的一部分:
This is one part of my Startup:
services.AddDbContext<MyContext>(options => options
.UseLazyLoadingProxies()
.UseNpgsql(Configuration.GetConnectionString("MyConnectionString"),
opt => opt.UseNodaTime()));
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My-API", Version = "v1" });
});
services.AddControllers()
.AddNewtonsoftJson();
这是我的动作:
[HttpPatch("{id}")]
public async Task<IActionResult> Patch(Guid id,
[FromBody] JsonPatchDocument<MyViewModel> patchDocument)
{
await this.service.HandlePatchAsync(id, patchDocument);
return NoContent();
}
这是身体内容:
[
{
"op": "replace",
"path": "/name",
"value": "New Name"
},
{
"op": "replace",
"path": "/country",
"value": "Germany"
}
]
有人知道这里出了什么问题吗?
Does anyone have an idea what is goung wrong here?
推荐答案
我遇到了类似的问题.我将完全摆脱Newtonsoft
,但是在那种情况下,带有JsonPatchDocument
的补丁无法正常工作.
I struggle with a similar issue. I was going to get rid of Newtonsoft
at all, but in that case the patch with JsonPatchDocument
was not working.
查看全文