You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/web-api/jsonpatch.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,8 +64,8 @@ This package provides a <xref:Microsoft.AspNetCore.JsonPatch.SystemTextJson.Json
64
64
In an API controller, an action method for JSON Patch:
65
65
66
66
* Is annotated with the <xref:Microsoft.AspNetCore.Mvc.HttpPatchAttribute> attribute.
67
-
* Accepts a <xref:Microsoft.AspNetCore.JsonPatch.JsonPatchDocument%601>, typically with [<xref:Microsoft.AspNetCore.Mvc.FromBodyAttribute>](xref:Microsoft.AspNetCore.Mvc.FromBodyAttribute).
68
-
* Calls <xref:Microsoft.AspNetCore.JsonPatch.JsonPatchDocument.ApplyTo(System.Object)> on the patch document to apply the changes.
67
+
* Accepts a <xref:Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument%601>, typically with [<xref:Microsoft.AspNetCore.Mvc.FromBodyAttribute>](xref:Microsoft.AspNetCore.Mvc.FromBodyAttribute).
68
+
* Calls <xref:Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument.ApplyTo(System.Object)> on the patch document to apply the changes.
69
69
70
70
### Example Controller Action method:
71
71
@@ -83,7 +83,7 @@ The sample action method's key steps:
83
83
* The method retrieves a `Customer` object from the database `AppDb` using the provided id.
84
84
* If no `Customer` object is found, it returns a `404 Not Found` response.
85
85
***Apply JSON Patch**:
86
-
* The <xref:Microsoft.AspNetCore.JsonPatch.JsonPatchDocument.ApplyTo(System.Object)> method applies the JSON Patch operations from the patchDoc to the retrieved `Customer` object.
86
+
* The <xref:Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument.ApplyTo(System.Object)> method applies the JSON Patch operations from the patchDoc to the retrieved `Customer` object.
87
87
* If errors occur during the patch application, such as invalid operations or conflicts, they are captured by an error handling delegate. This delegate adds error messages to the `ModelState` using the type name of the affected object and the error message.
88
88
***Validate ModelState**:
89
89
* After applying the patch, the method checks the `ModelState` for errors.
@@ -105,9 +105,9 @@ The following example shows the body of a `400 Bad Request` response for a JSON
105
105
106
106
## Apply a JSON Patch document to an object
107
107
108
-
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.
108
+
The following examples demonstrate how to use the <xref:Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument.ApplyTo(System.Object)> method to apply a JSON Patch document to an object.
109
109
110
-
### Example: Apply a <xref:Microsoft.AspNetCore.JsonPatch.JsonPatchDocument%601> to an object
110
+
### Example: Apply a <xref:Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument%601> to an object
111
111
112
112
The following example demonstrates:
113
113
@@ -177,14 +177,14 @@ The previous example results in the following output of the updated object:
177
177
}
178
178
```
179
179
180
-
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:
180
+
The <xref:Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument.ApplyTo(System.Object)> method generally follows the conventions and options of <xref:System.Text.Json> for processing the <xref:Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument%601>, including the behavior controlled by the following options:
181
181
182
182
*<xref:System.Text.Json.Serialization.JsonNumberHandling>: Whether numeric properties are read from strings.
183
183
*<xref:System.Text.Json.JsonSerializerOptions.PropertyNameCaseInsensitive>: Whether property names are case-sensitive.
184
184
185
-
Key differences between <xref:System.Text.Json> and the new <xref:Microsoft.AspNetCore.JsonPatch.JsonPatchDocument%601> implementation:
185
+
Key differences between <xref:System.Text.Json> and the new <xref:Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument%601> implementation:
186
186
187
-
* The runtime type of the target object, not the declared type, determines which properties <xref:Microsoft.AspNetCore.JsonPatch.JsonPatchDocument.ApplyTo(System.Object)> patches.
187
+
* The runtime type of the target object, not the declared type, determines which properties <xref:Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument.ApplyTo(System.Object)> patches.
188
188
*<xref:System.Text.Json> deserialization relies on the declared type to identify eligible properties.
189
189
190
190
### Example: Apply a JsonPatchDocument with error handling
@@ -196,7 +196,7 @@ JSON `Patch` supports the `test` operation, which checks if a specified value eq
196
196
The following example demonstrates how to handle these errors gracefully.
197
197
198
198
> [!Important]
199
-
> 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.
199
+
> The object passed to the <xref:Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument.ApplyTo(System.Object)> method is modified in place. The caller is responsible for discarding changes if any operation fails.
200
200
201
201
```csharp
202
202
// Original object
@@ -274,7 +274,7 @@ To minimize security risks when integrating JSON Patch functionality into their
274
274
***Scenario**: A malicious client submits a `copy` operation that duplicates large object graphs multiple times, leading to excessive memory consumption.
275
275
***Impact**: Potential Out-Of-Memory (OOM) conditions, causing service disruptions.
276
276
***Mitigation**:
277
-
* Validate incoming JSON Patch documents for size and structure before calling <xref:Microsoft.AspNetCore.JsonPatch.JsonPatchDocument.ApplyTo(System.Object)>.
277
+
* Validate incoming JSON Patch documents for size and structure before calling <xref:Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument.ApplyTo(System.Object)>.
278
278
* The validation must be app specific, but an example validation can look similar to the following:
0 commit comments