Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mykola384 opened this issue Feb 25, 2022 · 1 comment
Open

Comments

@mykola384
Copy link

mykola384 commented Feb 25, 2022

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?

@Morcatko
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants