I have a class including ActiveModel that needs to have some "associations", like this:
a = ActiveModelClass.new
a.user = User.find(1)
I'm just using an attr_accessor for this:
attr_accessor :user
### Elsewhere ###
a.user.name # => "Kevin"
So far so good. But now I want to serialize it into JSON:
json = a.to_json
b = ActiveModelClass.new(ActiveSupport::JSON.decode(json))
But now, user is a hash:
b.user.class # => Hash
How can I cleanly restore these "associations" as objects of the classes they originally were?