Here is a partial, naive solution to my problem - I will update it when I develop it.
function findDifferences(objectA, objectB) { var propertyChanges = []; var objectGraphPath = ["this"]; (function(a, b) { if(a.constructor == Array) {
And here is an example of how it will be used, and the data that it will provide (please excuse the long example, but I want to use something relatively non-trivial):
var person1 = { FirstName : "John", LastName : "Doh", Age : 30, EMailAddresses : [ "john.doe@gmail.com", "jd@initials.com" ], Children : [ { FirstName : "Sara", LastName : "Doe", Age : 2 }, { FirstName : "Beth", LastName : "Doe", Age : 5 } ] }; var person2 = { FirstName : "John", LastName : "Doe", Age : 33, EMailAddresses : [ "john.doe@gmail.com", "jdoe@hotmail.com" ], Children : [ { FirstName : "Sara", LastName : "Doe", Age : 3 }, { FirstName : "Bethany", LastName : "Doe", Age : 5 } ] }; var differences = findDifferences(person1, person2);
At this point, the differences array will look if you serialized it to JSON:
[ { "Property":"this.LastName", "ObjectA":"Doh", "ObjectB":"Doe" }, { "Property":"this.Age", "ObjectA":30, "ObjectB":33 }, { "Property":"this.EMailAddresses[1]", "ObjectA":"jd@initials.com", "ObjectB":"jdoe@hotmail.com" }, { "Property":"this.Children[0].Age", "ObjectA":2, "ObjectB":3 }, { "Property":"this.Children[1].FirstName", "ObjectA":"Beth", "ObjectB":"Bethany" } ]
The value of this in the Property value refers to the root of the object that was mapped. So, this solution is not quite what I need yet, but it is pretty close.
Hope this is useful to someone there, and if you have suggestions for improvement, Iβm all ears; I wrote this very late last night (that is, early in the morning), and there may be things that I completely ignore.
Thank.