Skip to content

Conversation

changa
Copy link

@changa changa commented Oct 8, 2013

This should solve #340.

When requiring Rails, as_json somehow ends up with a
JSON::Ext::Generator::State instance as arguments, instead of a plain old Hash,
which causes this:

2.0.0 (main):0 > require "active_model_serializers"
=> true
2.0.0 (main):0 > require "json"
=> true
2.0.0 (main):0 > JSON.dump  ActiveModel::Serializer.new(Object.new)
=> "\"#<ActiveModel::Serializer:0x007f7a2101a458>\""
2.0.0 (main):0 > require "rails"
=> true
2.0.0 (main):0 > JSON.dump  ActiveModel::Serializer.new(Object.new)
NoMethodError: undefined method `fetch' for #<JSON::Ext::Generator::State:0x007f7a2093bfb0>
from /home/drr/code/af/map/code/.bundle/ruby/2.0.0/gems/active_model_serializers-0.8.1/lib/active_model/serializer.rb:341:in `as_json'`'`

This should solve rails-api#340.

When requiring Rails, `as_json` somehow ends up with a
JSON::Ext::Generator::State instance as arguments, instead of a plain old Hash,
which causes this:

```
2.0.0 (main):0 > require "active_model_serializers"
=> true
2.0.0 (main):0 > require "json"
=> true
2.0.0 (main):0 > JSON.dump  ActiveModel::Serializer.new(Object.new)
=> "\"#<ActiveModel::Serializer:0x007f7a2101a458>\""
2.0.0 (main):0 > require "rails"
=> true
2.0.0 (main):0 > JSON.dump  ActiveModel::Serializer.new(Object.new)
NoMethodError: undefined method `fetch' for #<JSON::Ext::Generator::State:0x007f7a2093bfb0>
from /home/drr/code/af/map/code/.bundle/ruby/2.0.0/gems/active_model_serializers-0.8.1/lib/active_model/serializer.rb:341:in `as_json'`'`
```
@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 55425c5 on changa:fix_json_glitch_with_rails into 919bb38 on rails-api:master.

@spastorino
Copy link
Contributor

This works fine in current master. Thanks for helping.

@spastorino spastorino closed this Oct 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants