custom serialization: used ObjectIdDict in generation functions

The old solution also did not permit one to read a MyContainer
object without first writing one; this solution doesn't have
that problem.