flipkart-incubator / flipkart-incubator/zjsonpatch

Diff then patch fails on certain json

Open
#116 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
586
Forks
153
PR merge metrics
No merged PRs in 30d

Description

## Expected Behavior
If JsonDiff.asJson succeeds then JsonPatch.apply should succeed

## Actual Behavior
JsonPatch.apply fails with `[MOVE Operation] Missing field`

## Steps to Reproduce the Problem

```
ObjectMapper mapper = new ObjectMapper();
JsonNode source = mapper.readTree("{\"16\":[{\"id\":\"one\",\"type\":\"page\",\"length\":1}],\"63\":[{\"id\":\"two\",\"length\":2}],\"76\":[{\"id\":\"three\",\"length\":3}]}");
JsonNode target = mapper.readTree("{\"16\":[{\"id\":\"four\",\"length\":4}],\"76\":[{\"id\":\"five\",\"type\":\"page\",\"length\":5}]}");
JsonNode diff = JsonDiff.asJson(source, target);
JsonPatch.apply(diff, source);

[MOVE Operation] Missing field "77" at root
at com.flipkart.zjsonpatch.JsonPatch.process(JsonPatch.java:112)
at com.flipkart.zjsonpatch.JsonPatch.apply(JsonPatch.java:127)
at com.flipkart.zjsonpatch.JsonPatch.apply(JsonPatch.java:132)
```

## Specifications
The json looks contrived, but it is a real world example from comparing facebook posts.
Java 1.8, Jackson 2.9.9, zjsonpatch 0.4.9

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.