-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create DefaultSerializer so that as_json uses same interface. #207
Create DefaultSerializer so that as_json uses same interface. #207
Conversation
This is to ensure that PORO's as_json is called if no serializer is specified. Original behaviour was that serializable_hash was being called, overriding the as_json method.
@@ -20,5 +20,6 @@ Gem::Specification.new do |gem| | |||
gem.add_dependency 'activemodel', '>= 3.0' | |||
gem.add_development_dependency "rails", ">= 3.0" | |||
gem.add_development_dependency "pry" | |||
gem.add_development_dependency "pry-nav" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why'd this get added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oversight, it helped with some debugging. I'll remove it.
On Feb 10, 2013 11:37 AM, "Steve Klabnik" notifications@github.com wrote:
In active_model_serializers.gemspec:
@@ -20,5 +20,6 @@ Gem::Specification.new do |gem|
gem.add_dependency 'activemodel', '>= 3.0'
gem.add_development_dependency "rails", ">= 3.0"
gem.add_development_dependency "pry"
- gem.add_development_dependency "pry-nav"
Why'd this get added?
—
Reply to this email directly or view it on GitHubhttps://github.com//pull/207/files#r2955823..
This kinda bugs me, though it may be an issue with the test, and not with your feature. |
Yeah this bugs me too. Have to dig deeper here.
|
@steveklabnik I removed the |
Thanks! I wonder why the jruby tests are failing: https://travis-ci.org/rails-api/active_model_serializers/jobs/4723457 |
@steveklabnik hmm looks like it's failing when using Gemfile.edge. I get the same result on the master branch on my local machine. Need to dig deeper. |
Merge remote-tracking branch 'fblee/master'
…_serializer Fix rendering nil with custom serializer
'embed_key' option to allow embedding by attributes other than IDs
This doesn't merge cleanly any more, can you take a look? The Jruby thing shouldn't be an issue. |
Sure I'll take a look sometime this evening. Thanks. On 5 March 2013 16:06, Steve Klabnik notifications@github.com wrote:
|
Conflicts: lib/active_model/array_serializer.rb
@steveklabnik Merged. |
Now there's a bunch of test failures. :( In the future, please rebase rather than merge master back in. ❤️ |
@steveklabnik Ahh, the test failed in earlier versions because of a line break. I fixed it and it seems to be good now. And yep, I'll rebase in the future, cheers. |
Create DefaultSerializer so that as_json uses same interface.
Thank you! Duck typing ftw! ❤️ |
When adding acive_model_serializers as a gem in an exiting project, I noticed that it broke existing functionality, particularly when responding with an array of objects:
respond_with users
where User overrides
as_json
.I found that
ArraySerializers
was circumventing this method calling directly intoserializable_hash
.I took the idea of an old pull request (that was never merged in) and applied
DefaultSerializer
which simply calls into object'sas_json
whenserializable_hash
is called. This also provides a common interface.All tests pass.
I'm still not entirely sure if this is the right way of doing this, or what the implications are, but suffice to say this fixed my particular problem.