-
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
Serailize plain arrays #782
Conversation
9e8e3db
to
d66bf2c
Compare
Take a look at https://github.com/rails-api/active_model_serializers/blob/master/lib/action_controller/serialization.rb#L22. You can redefine |
Works great for me ! Thanks a lot @mitchlloyd. But your fork isn't going to be merged ? |
@mitchlloyd does my answer help you? |
I was going to fix the same issue #772 as @mitchlloyd but realized he already had done so. Is there any obstacle to getting this merged in? |
@mitchlloyd so, if you have The original bug (#722) was regarding arrays, instead. We need more opinions on this. |
@kurko I can see how throwing an exception when an object doesn't have a serializer could be a better experience than falling back to the default serialization behavior of Rails in some cases. I agree it would be nice to get more opinions on this though. If that's the conclusion then I'd be happy to change the PR to implement that behavior. However, in this particular case (from #772):
Should the user see an error? Another possibility might be to do a check upfront for primitive values like |
@mitchlloyd yes, I think we should whitelist those primitive types and have a baked-in serializer for them. As for the rest, my opinion is that we should just raise. |
d66bf2c
to
ce1a7b7
Compare
ce1a7b7
to
3cc390b
Compare
This new We still have the behavior where users will get an sub optimal error ( |
Propose to close as fixed by #962 (though I'm not 100% sure that is true) |
This PR is in response to #772
I wanted to learn about ActiveModelSerializers so I thought I'd try to tackle a bug. Unfortunately the one I picked lead me to some pretty big design questions.
Specifically:
Is there a way to avoid invoking all the guts of AMS on a "plain" array?
and what does it even mean to have primitive values in an array with serializable objects?
I'm sending this PR because it at least provides a failing test for the issue. If you have some helpful insights or If you think this PR might be usable let me know and I can work on any needed adjustments. Otherwise, feel no remorse about closing :)