title: Ruby on Rails serialize and then deserialize the same object in JSON
body: <p>I have spent days on this trying out all the JSON libraries including the JSON gem, Yajl-ruby, ActiveSupport::JSON and nothing can do this simple task:</p>
  
  <pre><code>user = User.find(1)
  json = user.to_json
  user2 = json.as_json # OR json.from_json 
                       # OR JSON.parse(json) 
                       # OR Yajl::Parser.parse(json)
                       # OR ActiveSupport::JSON.decode(json)
  </code></pre>
  
  <p>When I try to use the deserialized JSON data to create a new User, I get one of the following errors:</p>
  
  <pre><code>User.new(Yajl::Parser.parse(json))  
  # ActiveRecord::UnknownAttributeError: unknown attribute: json_class
  
  User.new(json.as_json)
  # NoMethodError: undefined method `stringify_keys!' for #&lt;String:0xb6de4318&gt;
  
  User.new(JSON.parse(json))
  # NoMethodError: undefined method `stringify_keys!' for #&lt;User:0xb6dc7470&gt;
  
  User.new(ActiveSupport::JSON.decode(json))
  # NoMethodError: undefined method `stringify_keys!' for #&lt;User:0xb6da3764&gt;
  </code></pre>
  
  <p>This is so easy to do with YAML using to_yaml and from_yaml. Why can't to_json produce the kind of JSON that from_json could convert back to a ruby object?</p>
  
  <p>Edit: I am using Rails 2.3.8, although I have tried 2.3.5 and 3.0.0. Also, I am using the json-rpc plugin to create a JSON-RPC service, although the same problem persists without the plugin.</p>