Further improvements to serialization

The first patch eliminates the interim hashmap in the serialization path.

The second patch makes the equality/hash functions final and reworks the serialization path to use default java serializer as much as possible (which will set the final fields for us).