Morcatko / Morcatko.AspNetCore.JsonMergePatch

JsonMergePatch support for ASP.NET Core
MIT License
88 stars 21 forks source link

NullReferenceException when patching from NULL to object #4

Closed edmacdonald closed 5 years ago

edmacdonald commented 6 years ago

I can't seem to get this scenario to work: Model {"a":"b"} Patch {"x":{"y":"z"}} Result {"a":"b", "x":{"y":"z"}}

To illustrate, in PatchTest.PatchObject() replace this line: await server.PostAsync("api/data/0", GetTestModel()); with this line: await server.PostAsync("api/data/0", new TestModel());

The error occurs when applying the underlying JsonPatch: _jsonPatchDocument.ApplyTo(objectToApplyTo);

The issue seems to be that there are operations for the subModel properties, but not for the subModel itself.

To test, I changed JsonMergePatchInputFormatter.AddOperation() to instead add a replace operation for the object property instead of recursing and it worked for this case, however it breaks the ability to patch nested properties.

-Ed

Morcatko commented 5 years ago

Fixed in 2.0.0-beta06 (thanks @bhugot)