candy icon indicating copy to clipboard operation
candy copied to clipboard

Need more robust serialization of non-Candy objects

Open SFEley opened this issue 15 years ago • 0 comments

Breaking on objects with parameters in their initializers is just too brittle. It'd be smarter to try a series of strategies, in order:

  1. to_mongo if the object responds to from_mongo
  2. to_json if the object responds to from_json
  3. The current Candy::Wrapper class-and-ivars serialization if the object initializer's arity is 0 (Note: make it even smarter if Method#parameters is implemented, as in Ruby 1.9.2.)
  4. Marshal.dump if the object responds to Marshal.load
  5. Throw an exception if none of the above works.

This is the chain of maximum usefulness within MongoDB queries or data loads. In any of those cases we'll still need to store the strategy used and the class name (except for Marshal).

SFEley avatar May 05 '10 18:05 SFEley