Add serialization and deserialization methods.