Skip to content

Need more robust serialization of non-Candy objects #9

Description

@SFEley

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).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions