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

Json Patch apply method is throwing JsonPatchException even if one property name is different #111

Open
anandhkishan opened this issue Oct 22, 2021 · 1 comment

Comments

@anandhkishan
Copy link

anandhkishan commented Oct 22, 2021

First of all great library support for JSON transformation 😃 👏 Was easy and intuitive on usage of it.
One thing that I noticed is when applying patch to the actual JSON -> if some of the attributes in actual JSON is not present in the operations, we are getting JsonPatchException
ref:
com.github.fge.jsonpatch.JsonPatchOperation#apply
com.github.fge.jsonpatch.JsonPatch#apply

For instance, I tried the following code snippet

JsonNode payloadNode = JsonLoader.fromString(payload);
JsonPatch jsonPatch = JsonPatch.fromJson(JsonLoader.fromString(specJson));
JsonNode transformedNode = jsonPatch.apply(payloadNode);

Here the specJson was:

{ "op": "move", "from": "/account_id", "path": "/app_id" }

And the payload was:
{ "tenant_id":2637,"account_id": 1231232123423}

Since payload has unknown property (tenant_id), this was throwing JsonPatchException exception.
The ask is what if there are some properties which needs no JsonPatch and can stay as it is?

Can we have another implementation which would suppress these exceptions that could happen when there are unknown attributes present in the actual JSON?

@anandhkishan
Copy link
Author

@fge If you could confirm that this new implementation can exist, I could start working on this and contribute to this change. Thanks!

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

1 participant