Package org.apache.juneau.bean.jsonpatch


package org.apache.juneau.bean.jsonpatch
Juneau @Marshalled types for JSON Patch (RFC 6902).
Overview

A JSON Patch document is a JSON array of operation objects describing changes to apply to a target JSON document. Each operation object has an op member naming one of the six operation types (add, remove, replace, move, copy, test), a path member (JSON Pointer per RFC 6901), and op-specific additional members. The matching ContentType constant is org.apache.juneau.http.header.ContentType#APPLICATION_JSON_PATCH.

Bean Classes
  • JsonPatchOperation - Abstract base. Polymorphic dispatch wired via @Marshalled(typePropertyName="op", dictionary={...}), so the parser materializes the correct concrete subclass keyed off the op member.
  • AddOp - op:"add" + value.
  • RemoveOp - op:"remove".
  • ReplaceOp - op:"replace" + value.
  • MoveOp - op:"move" + from.
  • CopyOp - op:"copy" + from.
  • TestOp - op:"test" + value.
  • JsonPatch - LinkedList<JsonPatchOperation>; the JSON Patch document serializes as a top-level JSON array (mirrors JsonSchemaArray).
Example

JsonPatch patch = new JsonPatch() .append(new AddOp("/a/b/c", "foo")) .append(new RemoveOp("/a/b/c")) .append(new ReplaceOp("/a/b/c", 42)) .append(new MoveOp("/a/b/c", "/a/b/d")) .append(new CopyOp("/a/b/c", "/a/b/e")) .append(new TestOp("/a/b/c", "foo")); String json = JsonSerializer.DEFAULT.write(patch); JsonPatch back = JsonParser.DEFAULT.read(json, JsonPatch.class);

See Also: