The Basic Mapping Tasks section in the B2B Integrator Guide describes how B2B performs maps. Many people overlook the behaviour and get bit during testing.
Copy by value: For strings only, B2B makes a copy of a source string to create the target string. Changing the source after mapping does not affect the target.
Copy by reference: For all other types of a pipeline varibles, B2B copies a reference. That is, the source and target variables aren’t the actual record, record list, string list, etc. Rather, these variables refer to the “real” object which is under the covers. When a map of a source record to a target record is done at the record level, changes to the source affects the target!
Review the B2B Integrator Guide for additional details.
Unfortunately, there is no way to generically overcome this. For each situation, you must devise an approach for “cloning” a source object if you want to make a copy. Using only flow services, you can clone a record by mapping fields from the bottom up. Start with the lowest level structure, if the record is nested, copying strings and then copy each structure on the way up. This will create a copy that is independent of the source.
Be careful if you decide to create a Java service to clone your objects. Java clone does NOT perform a “deep” copy of objects–it too has the copy by reference issue.