This was the cause of a quite difficult bug; in my application we create mapping classes and we have other uses for those mapping classes besides feeding them into JSON-mapper to create converters. The bug we were seeing was because json-mapper had replaced an object definition (subDocument above) with a function, it's own callback.
Principle of least surprise is that the module should not modify its arguments, instead returning a completely new object leaving the original mapping specification untouched. This makes it possible for us to keep using our data structures as-is.
Our present work-around is to deep clone the objects we have before we give them to json-mapper, so that we can retain a copy without modification.
When you call
makeConverter
on an object, the implementation of that function actually destructively modifies the source object.Sample test case to show the issue:
The source code that modifies the original object is here
This was the cause of a quite difficult bug; in my application we create mapping classes and we have other uses for those mapping classes besides feeding them into JSON-mapper to create converters. The bug we were seeing was because json-mapper had replaced an object definition (
subDocument
above) with a function, it's own callback.Principle of least surprise is that the module should not modify its arguments, instead returning a completely new object leaving the original mapping specification untouched. This makes it possible for us to keep using our data structures as-is.
Our present work-around is to deep clone the objects we have before we give them to json-mapper, so that we can retain a copy without modification.