Skip to content

Commit 47eab6a

Browse files
committed
Added xref links for all API mention.
1 parent c0ea3dd commit 47eab6a

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

aspnetcore/web-api/jsonpatch.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ uid: web-api/jsonpatch
1414

1515
This article explains how to handle JSON Patch requests in an ASP.NET Core web API.
1616

17-
JSON Patch support in ASP.NET Core web API is based on `System.Text.Json` serialization, and requires the [`Microsoft.AspNetCore.JsonPatch.SystemTextJson`](https://www.nuget.org/packages/Microsoft.AspNetCore.JsonPatch.SystemTextJson) NuGet package.
17+
JSON Patch support in ASP.NET Core web API is based on <xref:System.Text.Json> serialization, and requires the [`Microsoft.AspNetCore.JsonPatch.SystemTextJson`](https://www.nuget.org/packages/Microsoft.AspNetCore.JsonPatch.SystemTextJson) NuGet package.
1818

1919
**[JSON Patch](https://jsonpatch.com/)**:
2020

@@ -24,12 +24,12 @@ JSON Patch support in ASP.NET Core web API is based on `System.Text.Json` serial
2424

2525
In web apps, JSON Patch is commonly used in a PATCH operation to perform partial updates of a resource. Rather than sending the entire resource for an update, clients can send a JSON Patch document containing only the changes. Patching reduces payload size and improves efficiency.
2626

27-
JSON Patch support in ASP.NET Core web API is based on `System.Text.Json` serialization, starting with .NET 10. This release introduces a new implementation of `JsonPatch` based on `System.Text.Json` serialization. This feature:
27+
JSON Patch support in ASP.NET Core web API is based on <xref:System.Text.Json> serialization, starting with .NET 10. This release introduces a new implementation of <xref:Microsoft.AspNetCore.JsonPatch> based on <xref:System.Text.Json> serialization. This feature:
2828

29-
* Aligns with modern .NET practices by leveraging the `System.Text.Json` library, which is optimized for .NET.
29+
* Aligns with modern .NET practices by leveraging the <xref:System.Text.Json> library, which is optimized for .NET.
3030
* Provides improved performance and reduced memory usage compared to the legacy `Newtonsoft.Json`-based implementation. For more information on the legacy `Newtonsoft.Json`-based implementation, see the [.NET 9 version of this article](xref:web-api/jsonpatch?view=aspnetcore-9.0&preserve-view=true).
3131

32-
The following benchmarks compare the performance of the new `System.Text.Json` implementation with the legacy `Newtonsoft.Json` implementation:
32+
The following benchmarks compare the performance of the new <xref:System.Text.Json> implementation with the legacy `Newtonsoft.Json` implementation:
3333

3434
| Scenario | Implementation | Mean | Allocated Memory |
3535
|----------------------------|------------------------|------------|------------------|
@@ -46,22 +46,22 @@ These benchmarks highlight significant performance gains and reduced memory usag
4646
> [!IMPORTANT]
4747
> The JSON Patch standard has ***inherent security risks***. Since these risks are inherent to the JSON Patch standard, the new implementation ***doesn't attempt to mitigate inherent security risks***. It's the responsibility of the developer to ensure that the JSON Patch document is safe to apply to the target object. For more information, see the [Mitigating Security Risks](#mitigating-security-risks) section.
4848
49-
## Enable JSON Patch support with `System.Text.Json`
49+
## Enable JSON Patch support with <xref:System.Text.Json>
5050

51-
To enable JSON Patch support with `System.Text.Json`, install the [`Microsoft.AspNetCore.JsonPatch.SystemTextJson`](https://www.nuget.org/packages/Microsoft.AspNetCore.JsonPatch.SystemTextJson) NuGet package.
51+
To enable JSON Patch support with <xref:System.Text.Json>, install the [`Microsoft.AspNetCore.JsonPatch.SystemTextJson`](https://www.nuget.org/packages/Microsoft.AspNetCore.JsonPatch.SystemTextJson) NuGet package.
5252

5353
```dotnetcli
5454
dotnet add package Microsoft.AspNetCore.JsonPatch.SystemTextJson --prerelease
5555
```
5656

57-
This package provides a `JsonPatchDocument<T>` class to represent a JSON Patch document for objects of type `T` and custom logic for serializing and deserializing JSON Patch documents using `System.Text.Json`. The key method of the `JsonPatchDocument<T>` class is `ApplyTo`, which applies the patch operations to a target object of type `T`.
57+
This package provides a <xref:Microsoft.AspNetCore.JsonPatch.JsonPatchDocument%601> class to represent a JSON Patch document for objects of type `T` and custom logic for serializing and deserializing JSON Patch documents using <xref:System.Text.Json>. The key method of the <xref:Microsoft.AspNetCore.JsonPatch.JsonPatchDocument%601> class is <xref:Microsoft.AspNetCore.JsonPatch.JsonPatchDocument.ApplyTo(System.Object)>, which applies the patch operations to a target object of type `T`.
5858

5959
## Action method code
6060

6161
In an API controller, an action method for JSON Patch:
6262

63-
* Is annotated with the `HttpPatch` attribute.
64-
* Accepts a <xref:Microsoft.AspNetCore.JsonPatch.JsonPatchDocument%601>, typically with [`[FromBody]`](xref:Microsoft.AspNetCore.Mvc.FromBodyAttribute).
63+
* Is annotated with the <xref:Microsoft.AspNetCore.Mvc.HttpPatchAttribute> attribute.
64+
* Accepts a <xref:Microsoft.AspNetCore.JsonPatch.JsonPatchDocument%601>, typically with [<xref:Microsoft.AspNetCore.Mvc.FromBodyAttribute>](xref:Microsoft.AspNetCore.Mvc.FromBodyAttribute).
6565
* Calls <xref:Microsoft.AspNetCore.JsonPatch.JsonPatchDocument.ApplyTo(System.Object)> on the patch document to apply the changes.
6666

6767
Here's an example:
@@ -85,7 +85,7 @@ The sample action method:
8585
8686
### Model state
8787

88-
The preceding action method example calls an overload of `ApplyTo` that takes model state as one of its parameters. With this option, you can get error messages in responses. The following example shows the body of a 400 Bad Request response for a `test` operation:
88+
The preceding action method example calls an overload of <xref:Microsoft.AspNetCore.JsonPatch.JsonPatchDocument.ApplyTo(System.Object)> that takes model state as one of its parameters. With this option, you can get error messages in responses. The following example shows the body of a 400 Bad Request response for a `test` operation:
8989

9090
```json
9191
{
@@ -241,9 +241,9 @@ Example:
241241

242242
## Apply a JSON Patch document to an object
243243

244-
The following examples demonstrate how to use the `ApplyTo` method to apply a JSON Patch document to an object.
244+
The following examples demonstrate how to use the <xref:Microsoft.AspNetCore.JsonPatch.JsonPatchDocument.ApplyTo(System.Object)> method to apply a JSON Patch document to an object.
245245

246-
### Example: Apply a `JsonPatchDocument` to an object
246+
### Example: Apply a <xref:Microsoft.AspNetCore.JsonPatch.JsonPatchDocument%601> to an object
247247

248248
The following example demonstrates:
249249

@@ -313,15 +313,15 @@ The previous example results in the following output of the updated object:
313313
}
314314
```
315315

316-
The `ApplyTo` method generally follows the conventions and options of `System.Text.Json` for processing the `JsonPatchDocument`, including the behavior controlled by the following options:
316+
The <xref:Microsoft.AspNetCore.JsonPatch.JsonPatchDocument.ApplyTo(System.Object)> method generally follows the conventions and options of <xref:System.Text.Json> for processing the <xref:Microsoft.AspNetCore.JsonPatch.JsonPatchDocument%601>, including the behavior controlled by the following options:
317317

318-
* `NumberHandling`: Whether numeric properties are read from strings.
319-
* `PropertyNameCaseInsensitive`: Whether property names are case-sensitive.
318+
* <xref:System.Text.Json.Serialization.JsonNumberHandling>: Whether numeric properties are read from strings.
319+
* <xref:System.Text.Json.JsonSerializerOptions.PropertyNameCaseInsensitive>: Whether property names are case-sensitive.
320320

321-
Key differences between `System.Text.Json` and the new `JsonPatchDocument<T>` implementation:
321+
Key differences between <xref:System.Text.Json> and the new <xref:Microsoft.AspNetCore.JsonPatch.JsonPatchDocument%601> implementation:
322322

323-
* The runtime type of the target object, not the declared type, determines which properties `ApplyTo` patches.
324-
* `System.Text.Json` deserialization relies on the declared type to identify eligible properties.
323+
* The runtime type of the target object, not the declared type, determines which properties <xref:Microsoft.AspNetCore.JsonPatch.JsonPatchDocument.ApplyTo(System.Object)> patches.
324+
* <xref:System.Text.Json> deserialization relies on the declared type to identify eligible properties.
325325

326326
### Example: Apply a JsonPatchDocument with error handling
327327

@@ -332,7 +332,7 @@ JSON `Patch` supports the `test` operation, which checks if a specified value eq
332332
The following example demonstrates how to handle these errors gracefully.
333333

334334
> [!Important]
335-
> The object passed to the `ApplyTo` method is modified in place. The caller is responsible for discarding changes if any operation fails.
335+
> The object passed to the <xref:Microsoft.AspNetCore.JsonPatch.JsonPatchDocument.ApplyTo(System.Object)> method is modified in place. The caller is responsible for discarding changes if any operation fails.
336336
337337
```csharp
338338
// Original object
@@ -412,7 +412,7 @@ Consumers of these packages can integrate JSON Patch functionality into their ap
412412
* **Scenario**: A malicious client submits a `copy` operation that duplicates large object graphs multiple times, leading to excessive memory consumption.
413413
* **Impact**: Potential Out-Of-Memory (OOM) conditions, causing service disruptions.
414414
* **Mitigation**:
415-
* Validate incoming JSON Patch documents for size and structure before calling `ApplyTo`.
415+
* Validate incoming JSON Patch documents for size and structure before calling <xref:Microsoft.AspNetCore.JsonPatch.JsonPatchDocument.ApplyTo(System.Object)>.
416416
* The validation must be app specific, but an example validation can look similar to the following:
417417

418418
```csharp
@@ -433,9 +433,9 @@ public void Validate(JsonPatchDocument<T> patch)
433433
* **Scenario**: Patch operations can manipulate fields with implicit invariants, (for example, internal flags, IDs, or computed fields), violating business constraints.
434434
* **Impact**: Data integrity issues and unintended app behavior.
435435
* **Mitigation**:
436-
* Use POCO objects with explicitly defined properties that are safe to modify.
437-
* Avoid exposing sensitive or security-critical properties in the target object.
438-
* If no POCO object is used, validate the patched object after applying operations to ensure business rules and invariants aren't violated.
436+
* Use POCOs (Plain Old CLR Objects) with explicitly defined properties that are safe to modify.
437+
* Avoid exposing sensitive or security-critical properties in the target object.
438+
* If a POCO object isn't used, validate the patched object after applying operations to ensure business rules and invariants aren't violated.
439439

440440
### Authentication and authorization
441441

0 commit comments

Comments
 (0)