Mongoid equivalent of ActiveRecord's `serialize` method Mongoid equivalent of ActiveRecord's `serialize` method ruby ruby

Mongoid equivalent of ActiveRecord's `serialize` method


You don't need to serialize with MongoDB as far as you can store in fields Arrays and Hashes.

field :hash_params, type: Hashfield :array_params, type: Array


Sometimes you need use the Value Object pattern and the same function like composed_of, some people wants to deprecate this function in the future and than you want to use serialize of standard active record. Mongoid provide the same functionality to create Value object avoid the serialize method look , you can provide your custom serialization here http://mongoid.org/en/mongoid/docs/documents.html#custom_fields:

class Foo  include Mongoid::Document  field :params, type: String  field :custom_params , type: MyCustomParamsTypeend