Skip to content

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

Open

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?

Activity

  1. Morcatko commented on Apr 29, 2022

    @Morcatko
    Owner

    I guess it makes sense to ignore it in some cases. I think it should be optional - fail by default, but option to ignore it.

    Feel free to create a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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