Skip to content

Commit f9a5dbe

Browse files
committed
JsonPatchDocument不再使用JsonPatchContent
1 parent ecea0bd commit f9a5dbe

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

WebApiClientCore/Parameters/JsonPatchDocument.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
using System.Diagnostics;
44
using System.Diagnostics.CodeAnalysis;
55
using System.Net.Http;
6+
using System.Net.Http.Headers;
7+
using System.Net.Http.Json;
68
using System.Threading.Tasks;
79
using WebApiClientCore.Exceptions;
8-
using WebApiClientCore.HttpContents;
910

1011
namespace WebApiClientCore.Parameters
1112
{
1213
/// <summary>
1314
/// 表示将自身作为JsonPatch请求内容
1415
/// </summary>
1516
[DebuggerTypeProxy(typeof(DebugView))]
17+
[RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext.")]
1618
public class JsonPatchDocument : IApiParameter
1719
{
18-
/// <summary>
19-
/// 操作列表
20-
/// </summary>
20+
private static readonly MediaTypeHeaderValue mediaTypeHeaderValue = new("application/json-patch+json");
2121
private readonly List<object> operations = [];
2222

2323
/// <summary>
@@ -79,7 +79,7 @@ public Task OnRequestAsync(ApiParameterContext context)
7979
}
8080

8181
var options = context.HttpContext.HttpApiOptions.JsonSerializeOptions;
82-
context.HttpContext.RequestMessage.Content = new JsonPatchContent(this.operations, options);
82+
context.HttpContext.RequestMessage.Content = JsonContent.Create(this.operations, this.operations.GetType(), mediaTypeHeaderValue, options);
8383

8484
return Task.CompletedTask;
8585
}

0 commit comments

Comments
 (0)