Add a test case for table serialization and fix a bug it exposed