0

I have seen others with this same error, but it has been caused by something else so none of the responses have helped me. I have a class called Diff:

public class Diff {
    private String path;
    private String value;
    private Operation operation;
    public enum Operation {
        ADD, REPLACE, REMOVE
    }

    //getters and setters
}

I need to apply this to a Json object. When working with this, I use the following command on a Diff:

mapper.valueToTree(diff);

This returns an ObjectNode containing:

{"path":"hello","value":"there","operation":"ADD"}

I want to turn this into a JsonPatch that will be applied to a JsonNode. To get the JsonPatch, I use the following:

JsonPatch jsonPatch = JsonPatch.fromJson(mapper.valueToTree(diff));

This, however, will throw the following exception:

Can not deserialize instance of java.util.ArrayList out of FIELD_NAME token

Any idea why this is happening? There isn't even an ArrayList involved (to my knowledge)

user2869231
  • 1,431
  • 5
  • 24
  • 53
  • I don't think that's what that factory method is for. I think it strictly tries to deserialize the json you pass to a `JsonPatch` object. – Savior Apr 13 '16 at 16:16
  • hmm. the next step was to use jsonPatch.apply(jsonNode). To my knowledge, that is supposed to apply the patch to the json in jsonNode. In other words, if the patch contains an ADD, then the jsonNode would have an additional key: value pair containing the patch information – user2869231 Apr 13 '16 at 16:20
  • is there something else I should be using instead to do that? – user2869231 Apr 13 '16 at 16:21
  • I don't know that API well, but its creator is a Stack Overflow member so they'll probably be around shortly. In the meantime. I would use the [`JsonPatchOperation`](https://github.com/fge/json-patch/blob/master/src/main/java/com/github/fge/jsonpatch/JsonPatchOperation.java) type (and its subtypes) instead of rolling your own. – Savior Apr 13 '16 at 16:30

0 Answers0