ModeShape/modeshape — pull request #594 by rhauch (2012-11-10 16:36:49+00:00)
Title: MODE-1703 Corrected serialization of Schematic deltas 

Array objects were not being serialized/deserialized properly within the delta's operation instances (e.g., PutOperation).

Normally, all SchematicEntry (e.g., Documents containing values such as Arrays and other Documents) are serialized using BSON, and this works correctly in the non-clustered case. However, in the clustered case, the changes made to one Document are recorded to create a SchematicEntryDelta that is shipped across the Infinispan cluster. (This way we can ship only the changes to the SchematicEntry rather than the whole document.) Thus the problem only manifest itself in clustered configurations.

The actual problem stemmed from the fact that an SchematicEntryDelta and its Operation objects are all externalizable (with custom Externalizers). The Operation objects can contain individual values, Document or Array objects. These are also externalizable, but there was a single DocumentExternalizer for both Document and Array objects and the DocumentExternalizer wrote/read both to/from BSON.

However, the BSON format (which is simply a binary representation of JSON documents, with a few extra value types) is only valid for Documents; a standalone Array cannot be written in BSON format.

The solution was to use the DocumentExternalizer for Documents, but a new ArrayExternalizer for Arrays. This ArrayExternalizer still uses BSON, but it uses a subset of the BSON representation to serialize Array objects. But, it does work well and fixes the problem.

Quite a few new tests were added to verify that the various operations with various parameters are indeed externalizable. The tests don't cover all the permuations, but they do attempt to cover the different kinds of operations with documents and arrays.

To make the Operation objects easily testable, equals and hashCode methods were added to all the Operation subclasses. Additionally, all of the externalizers were manually reviewed for asymmetric read and write methods (e.g, writing an object to the ObjectOutputStream but reading an integer from the ObjectInputStream), and several asymmetries were found in the Externalizers for BSON value types that ModeShape doesn't currently use, and these asymmetries were corrected.

All unit and integration tests pass with these changes.

Note that this pull-request includes the correct submitted by @kcrimson in his [pull-request](https://github.com/ModeShape/modeshape/pull/592).