Package com.google.genkit.core.jsonpatch


package com.google.genkit.core.jsonpatch
RFC 6902 (JSON Patch) support for Genkit Java.

This package provides a hand-rolled, dependency-free RFC 6902 JSON Patch implementation operating on Jackson JsonNode. It is intentionally self-contained so that the diff output shape is controlled exactly — no external JSON-patch library is used.

Genkit uses JSON Patch to stream incremental changes to a session's custom state ( AgentStreamChunk.customPatch). The first patch of every agent turn is a whole-document replace at the root pointer (""); subsequent patches are incremental diffs.

Example usage:


 JsonNode from = mapper.readTree("{\"counter\":1}");
 JsonNode to   = mapper.readTree("{\"counter\":2}");

 // Compute a minimal patch
 JsonNode patch = JsonPatch.diff(from, to);
 // → [{"op":"replace","path":"/counter","value":2}]

 // Apply the patch (does not mutate 'from')
 JsonNode result = JsonPatch.apply(from, patch);
 // → {"counter":2}

 // Whole-document replace (first patch of a turn)
 JsonNode firstPatch = JsonPatch.wholeDocumentReplace(to);
 // → [{"op":"replace","path":"","value":{"counter":2}}]
 
See Also: