
Applying Differential SynchronizationĬreating patches requires that you have both before and after instances of an object from which to calculate the difference. It will be replaced with a more permanent solution in a later release.
JAVA FILE SYNCHRONIZATION PATCH
Note that JsonPatchMaker is a temporary solution to (de)serializing Patch objects to/from JSON Patch. Similarly, a Patch object can be created from a JsonNode like this: Patch patch = omJsonNode(jsonPatchNode) For example, to convert a Patch to a JsonNode containing JSON Patch: JsonNode jsonPatchNode = JsonPatchMaker.toJsonNode(patch) But Spring Sync offers JsonPatchMaker as a utility class to convert Patch objects to/from Jackson JsonNode instances where the JsonNode is an ArrayNode containing zero or more operations per the JSON Patch specification. Therefore, the patched Todo in these examples should be identical to the modified Todo after applying the patch to the original.Īs I mentioned, Patch is decoupled from any particular patch representation.

Note that the diff() and apply() methods are the inverse of each other. Once you have a Patch, it can be applied to an object by passing in the object to the apply() method: Todo patched = patch.apply(original, Todo.class) Here, the Diff.diff() method will compare the two Todo objects and produce a Patch that describes the difference between them. Patch patch = Diff.diff(original, modified) The easiest way to create a patch is to perform a difference between two Java objects: Todo original =. Future versions of Spring Sync may include support for other patch representations. That said, it is inspired by JSON Patch and Spring Sync provides support for creating and serializing Patch instances as JSON Patch. The Patch class aims to be generic, not associated directly with any particular representation of a patch. The Patch class is the centerpiece of this library, capturing the changes that can be applied to an object to bring it in sync with another object. Creating and applying patchesĪt its lowest level, Spring Sync provides a library for producing and applying patches to Java objects.

The examples given here refer to the Spring REST Todos example and/or the Todo class in that example project. As this is a new project, I thought it would be a good time to show you what Spring Sync can do. Earlier today, I announced the first milestone release of Spring Sync, a new project that addresses efficient communication between client applications and Spring backends by employing patch-based exchanges.
