Closed AleksandrLiakhavetsEPAM closed 1 year ago
Good question, I havent tested this behavior.
Yeah this doesn't work because System.Text.Json deserializes object as JsonElement
type and that type does not have writable setters.
You could however Deserialize jsonData as JsonNode
using System.Text.Json.Nodes;
[HttpPatch]
public IActionResult Patch([FromBody] JsonPatchDocument patchDoc)
{
var jsonData = """"
{
"number": 1111
}
"""";
var obj = JsonSerializer.Deserialize<JsonNode>(jsonData)!;
patchDoc.ApplyTo(obj);
return Ok(patchDoc);
}
Maybe that suits your need?
Thank you for your answer. Will try to with it.
Does the patch work for the object type? I tried this method but was unsuccessful...
Request:
Handler
Exceptions
he target location specified by path segment 'number' was not found.