The best way is to serialize the object so that it saves and restores back.