Skip to content

Columns not in the model cause Patch based on NewtonsoftJson to crash #51

@mykola384

Description

@mykola384

When you send a json to patch, when the json has fields missing from the model, when it is a class, the exception "System.InvalidOperationException : Sequence contains no matching element" is thrown.

To reproduce it, go to the unit test Morcatko.AspNetCore.JsonMergePatch.Tests.NewtonsoftJson.Patching.Attributes.CannotPatchSubObject and change

"{'obj_property': { 'id': 3 }}");

to

"{'obj_other_property': { 'id': 3 }}");

I tracked it down to Morcatko.AspNetCore.JsonMergePatch.Internal.ReflectionHelper.GetJsonProperty which calls Single on properties list and the list is missing the specified property.

I think it would be useful to be able to patch a json with a document that has a random json inside - as when you have a document DB as a storage, you don't always need to have a strongly typed structure to store it.

Maybe, there are alternatives in how to do it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions