Making serialization/deserialization more generic