The right answer is: "Don't do this". There are many reasons why this is likely to go wrong:
- Your code will run in an environment that is different from the environment when it was saved. Either because it's on a different system, or because your application version is now slightly different. The last point is something that you will likely only run into once you have deployed the application to users, and then updated it 6 months later, and then suddenly everything goes wrong for your users, while it works for you.
- Security: You mix data and code, and that is likely to cause serious security problems. You think they don't apply to your case - until they do.
What you want to do instead is to separate data and code:
- Create a function to extract only the data from your object
- Create another function to load that data into your object
- Make sure that your load function can deal with older versions of the data.