NullPointerException in hashCode() when deserializing an object graph

The problem seems to be caused by the circular relationship between ManagingContainer and Container. When Container is deserialized it in turn deserializes the ManagingContainer referenced by the 'container' property. However, as this deserializes it tries to populate the HashSet with the Container which is in the process of being deserialized.

If you serialize/deserialize instead your ManagingContainer it should work fine as the Containers would be fully loaded before hashCode() is called. Alternatively, rethink your object graph to remove the circular dependency or write custom object read/write methods.