Skip to content

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

Open
@anandhkishan

Description

@anandhkishan

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions