How to recursively calculate the diff between two objects in a way that can be applied to generate either object from the other?

Viewed 98

I start with two complex objects, a and b, which can each contain anything, including other serializable objects or arrays. I want to get the diff of a and b in a way that I can 'apply' that patch to a to get b, or 'apply it in reverse' to b to get a. In other words, I want to be able to make a round trip, no matter how complex either object.

The reason I need this is that I want to be able to return to the various states of a record in a database over time. Every time the record changes, I want to store a patch, and I want to be able to play through the patches forward or backward to get to any previous state of that record.

Assuming I need to write this myself, I'm curious if there's an accepted standard for diff patches so that the tool I'd create might adhere to some sort of standards.

Any help would be greatly appreciated.

0 Answers
Related