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