> I was basing it on this article (as well as a stack overflow answer) that you 
> can provide a custom serializer in Rails 3.1:
>  
> http://edgerails.info/articles/what-s-new-in-edge-rails/2011/03/09/custom-activerecord-attribute-serialization/index.html
>  
> JSON provides a dump and load method on the class so it should be acceptable 
> as the serializer.
>  
> Is this article incorrect or my understanding of it?
Having just had a read of ActiveRecord::Base, I still can't see how I go wrong…

Base#serialize (line 557 of base.rb in ActiveRecord 3.1.0)

if the object supplied as the second argument responds to :load and :dump 
(which JSON does), then it uses that object, if not it wraps it in a YAMLColumn 
and sets the entry in serialized_attributes to that object.  Then in:

Base#arel_attributes_values (line 1963 of base.rb in ActiveRecord 3.1.0)

if there is an entry in serialized_attributes for a given attribute name (with 
a value put in to the coder variable) it calls coder.dump with the attribute 
value.

So, I can't understand why JSON wouldn't work as a second parameter...

Cheers,


Andy

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to